 |
Subscribe to this site |
|
Nullsafe and Conditions

Published 4 months ago
by
S V
//Sample groovy script
try{
def Line1 = [ContactRoleId:"300000333771225", Status: "S",ShipFromPartyId:null]
def Line = null
def Header = [FulfillOrgId_Custom: "OrgId1234",CustomerId : "Cust1234"]
String InvOrgID = "";
String status = "";
def Res
if (Line?.ShipFromPartyId == null )
{
InvOrgID = "X";
}
else
{
InvOrgID = "Y";
}
println("Value of InvOrgID: " + InvOrgID);
//Line?.Status makes sure that even if Line does not exist, it does not throw nullpointer. ? is the nullsafe operator
status = Line?.Status;
println("Value of status: " + status);
def Result = [InvOrgID: (Line?.ShipFromPartyId?:Header.FulfillOrgId_Custom), EBSOrderNumber:(Line?.ContactRoleId ?: Header.CustomerId)]
println("Value of Result: " + Result);
}
catch (ex)
{
println('ERROR : ' + ex.getMessage());
}