cancel
Showing results for 
Search instead for 
Did you mean: 

check if object is locked by user ?

itaKraus
Explorer
0 Kudos
414

hi
Hello everyone

I register a withdrawal
and receives into the variable every SALES ORDER according to the parameters I chose

Right now I want to go through all the results obtained from the fetch
and check whether the record is locked by a system user or not

 

How to write such a code in ABSL

I hope you can send me a serial code example!

I want to verify a lock on the SALES ORDER object

Accepted Solutions (0)

Answers (2)

Answers (2)

HarshalVakil
Active Contributor
0 Kudos

Hello,

Can you check if following works?

var currentDate = Context.GetCurrentGlobalDateTime();
var currentDate1 = currentDate.ConvertToLocalNormalisedDateTime();
var SalesOrders = SalesOrder.QueryByElements;
var SalesOrderDate_SelParams = SalesOrders.CreateSelectionParams();
SalesOrderDate_SelParams.Add(SalesOrders.Status.ItemListCustomerOrderLifeCycleStatusCode, "I", "EQ", "1");
SalesOrderDate_SelParams.Add(SalesOrders.Status.ItemListCustomerOrderLifeCycleStatusCode, "I", "EQ", "2");

var SalesOrderData_Results = SalesOrders.Execute(SalesOrderDate_SelParams);
var SalesOrderData_ResultsCopy = SalesOrders.Execute(SalesOrderDate_SelParams);

var ordersToRemove = new List<SalesOrderType>();

foreach (var SO in SalesOrderData_ResultsCopy)
{
var uuid = Library::UUID.ParseFromString(SO.UUID.content.ToString()); // sales order id
var messages;
var lock = BOAction.CheckLock("SalesOrder", "http://sap.com/xi/AP/CRM/Global", "Root", uuid);
messages = lock.MessageTypeItem;

var validationFailed = false; // Reset for each iteration

if (!lock.IsInitial() && messages.Count() > 0)
{
foreach (var message in messages)
{
if (message.MessageSeverityText == "E" && message.MessageID.content == "CL_CDA_DOCHD/000")
{
validationFailed = true;
ordersToRemove.Add(SO); // Mark for removal
lock.Clear();
break; // Break the inner loop since we already know this order is locked
}
}
messages.Clear();
}
}

// Remove all marked orders after the loop
foreach (var orderToRemove in ordersToRemove)
{
SalesOrderData_Results.Remove(ins => ins.ID.content == orderToRemove.ID.content);
}


Regards,
Harshal

itaKraus
Explorer
0 Kudos

HI 

Thank you very much for wanting to help and donating your time
The option you suggested is not available to me
I can't register
salesOrder.IsLockedByUser()

I am attaching the code with which I thought to perform the test
Maybe this will give you a direction on how I can check if an adder is locked

The problem is in the code
that when it runs in a loop and checks whether an order is locked or not
After he found some locked order
It does not continue to recheck properly
but as if treating all other orders as if they were locked
For example if order number 150 is currently locked
So all orders after this number are also considered locked


below is my code :

------------------------------------------------

var currentDate = Context.GetCurrentGlobalDateTime();
var currentDate1 = currentDate.ConvertToLocalNormalisedDateTime();
var SalesOrders = SalesOrder.QueryByElements;
var SalesOrderDate_SelParams = SalesOrders.CreateSelectionParams();
SalesOrderDate_SelParams.Add(SalesOrders.Status.ItemListCustomerOrderLifeCycleStatusCode, "I", "EQ", "1");
SalesOrderDate_SelParams.Add(SalesOrders.Status.ItemListCustomerOrderLifeCycleStatusCode, "I", "EQ", "2");
 
 
 
var SalesOrderData_Results = SalesOrders.Execute(SalesOrderDate_SelParams);
var SalesOrderData_ResultsCopy = SalesOrders.Execute(SalesOrderDate_SelParams);
 
 
foreach (var SO in SalesOrderData_ResultsCopy)
{
 
var uuid;
uuid = Library::UUID.ParseFromString(SO.UUID.content.ToString());// sales order id
var messages;
var lock;
 
lock = BOAction.CheckLock("SalesOrder", "http://sap.com/xi/AP/CRM/Global", "Root", uuid);
messages = lock.MessageTypeItem;
var validationFailed : Common:Indicator=false;
var a;
if (!lock.IsInitial() && messages.Count() > 0)
{
foreach (var message in messages)
{
 
if (message.MessageSeverityText == "E" && message.MessageID.content == "CL_CDA_DOCHD/000")
{
validationFailed = true;
a = SalesOrderData_Results.Remove(ins => ins.ID.content == SO.ID.content);
SalesOrderData_Results = a;
lock.Clear();
 
 
 
}
}
messages.Clear();
}
}
 


------------------------------------------------

I mean, actually my code is not completely correct and I probably don't check it in the right way

Anyone who can help me, I would be very happy

thanks