Thursday, July 13, 2023

Restrict the user to open the particular Form, if the same form already opened by any other user.

 In my scenario when I open particular SalesOrder i want to restrict to others by throwing an error “The same Salesorder is already opened by any other user”



1. Firstly add one field in SalesTable. 
2. Navigation  AOT -> Tables -> SalesTable.
3.Create new field  userId Datatype is string.

Navigate to Forms\SalesTable\Methods\init, write the following code in it.
public void init()
{
 
         SalesTable    salestablecpy ;
         FormRun       callerForm;

        salestablecpy  = element.args().record();
        callerForm       = element.args().caller();

        If (!salestablecpy.UserId)
        {
            ttsBegin;

                 salestablecpy.UserId = curUserId();
                  salestablecpy.doUpdate();
            ttsCommit;
        
        }
       else if(salestablecpy.UserId != curUserId())
       {
      
            throw error(strFmt("The same Salesorder(%1) is already opened by %2",                                                                 salestablecpy.SalesId,salestablecpy.UserId));

       }
}

. Similarly, navigate to  Forms\SalesTable\Methods\Close,  write the following code in it.




void  close()
{  
        SalesTable    salestablecpy, saleesTableLoc  ;
        formrun      formrun ;

       salestablecpy = element.args().record();

       formrun = element.args().caller();

      if (salestablecpy.UserId)
      { 
           ttsBegin;

           select forUpdate saleesTableLoc  where saleesTableLoc.RecId==salestablecpy.RecId;
           saleesTableLoc.UserId = ' ';
           saleesTableLoc.doUpdate();

           ttsCommit;
   
    }

}

No comments:

Post a Comment

adding new node in hierarcy type in workflow

class: WorkflowHierarchyProviderHelper  for convert nodetype  [ExtensionOf(classstr(WorkflowHierarchyProviderHelper))] public  final class ...