cancel
Showing results for 
Search instead for 
Did you mean: 

Overwrite Ship to Address of Sale order VIA ABSL

former_member535084
Participant
0 Kudos
464

Hello Experts,

I try to overwrite Ship to address in Sale order, but I got the message "Must not be changed".

import ABSL;
import AP.CRM.Global;


// define SalesOrder root node


var elSalesOrder_Root: elementsof SalesOrder;


var instSalesOrder;


// define SalesOrder item node


var elSalesOrder_Item: elementsof SalesOrder.Item;


var instSalesOrder_Item;


elSalesOrder_Root.Name.content = "Heat Transfer Specialists";


elSalesOrder_Root.BuyerID.content = "Check";






// SalesOrder: create new instance


instSalesOrder = SalesOrder.Create(elSalesOrder_Root);


//Account




instSalesOrder.Party.GetFirst().RoleCode = "1001";


instSalesOrder.Party.GetFirst().PartyKey.PartyID.content = "CP100140";


var saveAccountData = instSalesOrder.Party.Create();





//Process Ship to Address


if(instSalesOrder.ProductRecipientParty.AddressSnapshot.IsSet())
{
	var address = instSalesOrder.ProductRecipientParty.AddressSnapshot.PostalAddress.GetFirst();


	
	address.CountryCode = "US";


	address.RegionCode.content = "AK";


	address.CityName = "CHARLOTTE";


	address.StreetPostalCode="28269-0000";


	address.StreetName="7777 STATESVILLE ROAD";
}
else
{
	var address = instSalesOrder.ProductRecipientParty.AddressSnapshot.PostalAddress.Create();

	address.RegionCode.content = "AK";


	address.CityName = "CHARLOTTE";


	address.StreetPostalCode="28269-0000";


	address.StreetName="7777 STATESVILLE ROAD";



}



//Item


elSalesOrder_Item.ID = "1";
instSalesOrder_Item = instSalesOrder.Item.Create(elSalesOrder_Item);


instSalesOrder_Item.ItemProduct.ProductKey.ProductID.content = "P100205";




 
 if (instSalesOrder_Item.FirstRequestedItemScheduleLine.IsSet()) {


// set product quantity and UOM (will be defaulted by the system if not set)


instSalesOrder_Item.FirstRequestedItemScheduleLine.Quantity.content = 10;


instSalesOrder_Item.FirstRequestedItemScheduleLine.Quantity.unitCode = "EA";


} else {


instSalesOrder_Item.FirstRequestedItemScheduleLine.Create();


instSalesOrder_Item.FirstRequestedItemScheduleLine.Quantity.content = 10;


instSalesOrder_Item.FirstRequestedItemScheduleLine.Quantity.unitCode = "EA";


}


//discount header


if(instSalesOrder.PriceAndTaxCalculation.MainDiscount.IsSet())
{
	var discount = instSalesOrder.PriceAndTaxCalculation.MainDiscount;


	discount.TypeCode.content = "0007";
	discount.Rate.DecimalValue= -20;
	discount.Rate.MeasureUnitCode = "P1";
}
else
{
	var discount = instSalesOrder.PriceAndTaxCalculation.MainDiscount.Create();
	discount.TypeCode.content = "0007";
	discount.Rate.DecimalValue= -20;
	discount.Rate.MeasureUnitCode = "P1";
}


//Charge header
if(instSalesOrder.PriceAndTaxCalculation.MainSurcharge.IsSet())
{
	var discount = instSalesOrder.PriceAndTaxCalculation.MainSurcharge;


	discount.TypeCode.content = "7PR8";
	discount.Rate.DecimalValue= 30;
	discount.Rate.CurrencyCode = "USD";
}
else
{
	var discount = instSalesOrder.PriceAndTaxCalculation.MainSurcharge.Create();
	discount.TypeCode.content = "7PR8";
	discount.Rate.DecimalValue= 30;
	discount.Rate.CurrencyCode = "USD";
}

How can I Overwrite Ship to Address of Sale order when I create SO by ABSL?

Regards,

Quyen

former_member535084
Participant
0 Kudos

@may.thitsaoo ,horst.schaude

Do you have any idea ?

Thank

Quyen

Accepted Solutions (0)

Answers (4)

Answers (4)

0 Kudos

Try something like this:

import AP.FO.Address.Global; 
.......


var currentAddressSnap = yourSalesOrder.Party.Where(w=> w.RoleCode == "your role code").GetFirst().AddressSnapshot;

var add_NodeData : elementsof AddressSnapshot;
add_NodeData.SourceObjectNodeReference.ObjectNodeTypeCode.content = currentAddressSnap.SourceObjectNodeReference.ObjectNodeTypeCode.content ;
add_NodeData.SourceObjectNodeReference.ObjectTypeCode.content = currentAddressSnap.SourceObjectNodeReference.ObjectTypeCode.content;
add_NodeData.SourceObjectNodeReference.UUID.content = currentAddressSnap.SourceObjectNodeReference.UUID.content;
add_NodeData.SourceValidityPeriod.EndDateTime = currentAddressSnap.SourceValidityPeriod.EndDateTime;
add_NodeData.SourceValidityPeriod.StartDateTime = currentAddressSnap.SourceValidityPeriod.StartDateTime;

var add = AddressSnapshot.Create(add_NodeData);
if (add.IsSet()) 
{
	var p1 = add.PostalAddress.Create();
	p1.CityName = ""; 
	p1.CountryCode = "";
	p1.RegionCode.content = "";
	p1.StreetPostalCode = "";
	p1.StreetName = "";
        
        var currentAddress = yourSalesOrder.Party.Where(w=> w.RoleCode == "your role code").GetFirst();
	currentAddress.AddressReference.AddressHostUUID = add.UUID;
}


kuhn_tobias
Explorer
0 Kudos

Hi Quyen,

as horst.schaude already mentioned, an Address Snapshot can not be changed. You have to create an new Address Snapshot Instance with your wanted information an set this new instance as the current instance to Sales Order.

This new Instance Creation is in the SAP Business ByDesing Standard handled by the Address EC but in this case you have to do this via ABSL and I know that will make this task not as easy as expected ;-).

In worst case you could create an new Address Snapshot with an web service request (own in and out Web Service) in the system and then use the created instance in the sales order.

Best regards

Tobias Kuhn

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Quyen,

I do not mean to overwrite it in the Account, but in the SalesOrder. 🙂

Bye,
. Horst

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Quyen,

In general: A Snapshot cannot be changed at all. 😞

You need to find the correct place where the ship-to-address is maintained.

HTH,
. Horst

former_member535084
Participant
0 Kudos

Hello Horst,

I do not want to overwrite the current ship to that setup default in Account.

The ship-to address only is used one time for the SO.

Regards,

Quyen