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.
{
SalesTable salestablecpy ;
FormRun callerForm;
salestablecpy = element.args().record();
If (!salestablecpy.UserId)
{
salestablecpy.UserId = curUserId();
salestablecpy.doUpdate();
ttsCommit;
callerForm = element.args().caller();
{
ttsBegin;
salestablecpy.doUpdate();
ttsCommit;
}
else if(salestablecpy.UserId != curUserId())
{
formrun = element.args().caller();
if (salestablecpy.UserId)
{
ttsBegin;
select forUpdate saleesTableLoc where saleesTableLoc.RecId==salestablecpy.RecId;
saleesTableLoc.UserId = ' ';
saleesTableLoc.doUpdate();
ttsCommit;
}
{
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