Sunday, 19 June 2011

Script for enrolling students for multiple courses


Account Activity List Applet:
Server Script

function WebApplet_InvokeMethod (MethodName)
{
if (MethodName == "ShowPopup")
 {
 var sIds = "";
 var sTypeAct = "";
 var sDescAct = "";
 var bc = this.BusComp();
 var isRec = bc.FirstSelected();
 while(isRec)
 {

 var sId = bc.GetFieldValue("Id");
 var sType = bc.GetFieldValue("Type");
 var sDesc = bc.GetFieldValue("Description");
 //sIds = sIds +","+ sId;
 sTypeAct = sTypeAct+","+sType;
 sDescAct = sDescAct+","+sDesc


 isRec = bc.NextSelected();
 }

 TheApplication().SetProfileAttr("SRes", sId); //sIds
 TheApplication().SetProfileAttr("Type", sTypeAct);
 TheApplication().SetProfileAttr("Desc", sDescAct);

 //TheApplication().RaiseErrorText("Hai :"+sIds);
 return (CancelOperation);
 }

            return (ContinueOperation);
}

Test Popup Applet:


Browser Script:

function Applet_PreInvokeMethod (name, inputPropSet)
{

if(name == 'PickRecord')
{
if(confirm("Do you want to Copy Student info"))
return ("ContinueOperation");
else
return ("CancelOperation");
return ("ContinueOperation");
}

}


Final:
Server Script

function WebApplet_PreInvokeMethod (MethodName)
{

    if (MethodName == "PickRecord")
    {
              var bc = this.BusComp();
             var isRec = bc.FirstSelected();
                        if(isRec)
                         {
                                      var srowId = bc.GetFieldValue("Id");
  
                        } //IF

             var sTestRes = TheApplication().GetProfileAttr("SRes");
             var sType = TheApplication().GetProfileAttr("Type");
            var sDesc = TheApplication().GetProfileAttr("Desc");
            //TheApplication().RaiseErrorText("Hai:"+sType);

            var sMsg;
            var sMsg1;
             var bo = TheApplication().GetBusObject("Account");
            var bc = bo.GetBusComp("Account");
             var bc1 = bo.GetBusComp("Action");
     
            with(bc)
                {
                         bc.ActivateField("Id");
                         bc.ClearToQuery();
                         bc.SetViewMode(3);
                         bc.SetSearchSpec("Id", srowId);
                          bc.ExecuteQuery(ForwardOnly);
                         var isRec1 = bc.FirstRecord();
            var sAccountId = bc.GetFieldValue("Id");
    if(isRec)
    {
      with(bc1)
      {
     
    var sTypeRecArray = sType.split(",");
    var sDescRecArray = sDesc.split(",");
           
            for(var i = 1; i < sTypeRecArray.length; i++)
            {
//checking        
              bc1.ActivateField("Type");
                         bc1.ClearToQuery();
                         bc1.SetViewMode(3);
                         bc1.SetSearchSpec("Type", sTypeRecArray[i]);
                          bc1.ExecuteQuery(ForwardOnly);
                         var isRec2 = bc1.FirstRecord();
               if(isRec2)
               {
               TheApplication().RaiseErrorText("Record Exist of type:"+sTypeRecArray[i]);
               }
               else
               {                            //checking
                        sMsg = sTypeRecArray[i];  
                bc1.NewRecord(NewAfter);
        // bc1.SetFieldValue("Account Id", sTestRes);
         bc1.SetFieldValue("Type", sTypeRecArray[i]);
         bc1.SetFieldValue("Description", sDescRecArray[i]);
         bc1.WriteRecord();
       }                              //checking
   }
       
        } //WITH
        }   //IF
        }  //WITH          
         

  return (CancelOperation);
 } //METHOD
// TheApplication().SetProfileAttr("SRes", sIds);
     
            return (ContinueOperation);
}

No comments:

Post a Comment