cancel
Showing results for 
Search instead for 
Did you mean: 

How to Retrieve ShipFromItemLocation from CustomerInvoice

0 Kudos

My code in sap cloud studio:

var dataLocation;
var data = CustomerInvoice.Retrieve(this.GetFirst().ID);
if(data.IsSet())
{
   if(data.Item.GetFirst().IsSet())
   {
	  if(data.Item.GetFirst().ItemOriginCustomerInvoiceItemReference.IsSet())
	  {
	     if(data.Item.GetFirst().ItemOriginCustomerInvoiceItemReference.CorrespondingCustomerInvoiceRequestItem.IsSet())
		 {
		    if(data.Item.GetFirst().ItemOriginCustomerInvoiceItemReference.CorrespondingCustomerInvoiceRequestItem.ShipFromItemLocation.IsSet())
			{
				dataLocation = data.Item.GetFirst().ItemOriginCustomerInvoiceItemReference.CorrespondingCustomerInvoiceRequestItem.ShipFromItemLocation.LocationID.content;
			}
		 }
	  }
   }
}

Object for ItemOriginCustomerInvoiceItemReference not retrieve the data. in the form print out ShipFromItemLocation have value.

VVancalbergh
Contributor

Hi, I don't have the answer, but I do have important remarks. So I'm posting this as a comment:

- If your code was created with "Mass Enabled" on, then "this" is a collection. You should treat it as if it can contain one or more objects. Otherwise if later your code gets called with multiple objects in this, you will only process the first one.

- Don't repeat node navigations: If you're writing "data.Item.GetFirst()" twice, put it on a variable. Otherwise ByD will fetch the node twice which is bad for performance.

- Use more descriptive variable names. Like "invoice" instead of "data". This will help reading your code once it gets bigger.

Example:

foreach (var obj in this)
{
  var invLocation;
  var inv = CustomerInvoice.Retrieve(obj.ID);
  if (inv.IsSet())
  {
    var invFirstItem = inv.Item.GetFirst();
    if (invFirstItem.IsSet())
    {
      var ref = invFirstItem.ItemOriginCustomerInvoiceItemReference;
      if (ref.IsSet())
      {
        var reqItem = ref.CorrespondingCustomerInvoiceRequestItem;
        if (reqItem.IsSet())
        {
          var shipLoc = reqItem.ShipFromItemLocation;
          if (shipLoc.IsSet())
          {
            invLocation = shipLoc.LocationID.content;
          }
        }
      }
    }
  }
}

This will all help you a lot later.

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

thank you Vincent, I have fix this issue by retrieve from invoice request.

Answers (0)