/*
Add your SAP Business ByDesign scripting language implementation for:
Business Object: GoodsAndActivityConfirmation
Node: Root
Event: BeforeSave
Note:
- To access the elements of the business object node,
use path expressions, for example, this.<element name>.
- To use code completion, press CTRL+J.
- The solution uses this script when:
- the instance of the business object is being saved.
- the instance of the business object is created from other sources like web services, preview screen, and so on.
*/
import ABSL;
import AP.Common.GDT;
import AP.FO.ProductDataMaintenance.Global;
import AP.LogisticsExecution.Global;
var stringInput : DataType::LANGUAGEINDEPENDENT_EXTENDED_Text;
var stringLoopVal : DataType::LANGUAGEINDEPENDENT_EXTENDED_Text;
var stringHexVal : DataType::LANGUAGEINDEPENDENT_EXTENDED_Text;
var Body : DataType::LANGUAGEINDEPENDENT_EXTENDED_Text;
var productId : DataType::LANGUAGEINDEPENDENT_EXTENDED_Text;
var serialId : DataType::LANGUAGEINDEPENDENT_EXTENDED_Text;
var root : elementsof GoodsAndActivityConfirmation;
var invChgItem = this.InventoryChangeItem;
if (this.BaseBusinessTransactionDocumentReference.TypeCode == "73" && this.CancellationDocumentIndicator == false)
{
foreach (var invCItem in invChgItem)
{
if (invCItem.InventoryMovementDirectionCode == "1")
{
var prodID = invCItem.InventoryItemChange.MainInventorySeparatingValues.MaterialKey.ProductID.content;
var invItemChgSNo = invCItem.InventoryItemChangeSerialNumber;
var indProd : IndividualProduct.ServiceProcessInformation.SerialNumberIdentification.SerialNumberIdentificationOverview;
var qrySerialID = indProd.QueryByElements;
var selParm = qrySerialID.CreateSelectionParams();
selParm.Add(qrySerialID.ParentRefProductKey.ProductID.content, "I", "EQ", prodID);
foreach (var invSlNo in invItemChgSNo)
{
selParm.Add(qrySerialID.ParentSerialID, "I", "EQ", invSlNo.SerialID);
var result = qrySerialID.Execute(selParm);
stringInput.Clear();
foreach (var resultLine in result)
{
stringLoopVal.Clear();
productId = resultLine.ReferencedProductKey.ProductID.content.RemoveLeadingZeros();
serialId = resultLine.IndividualProductSerialNumberKey.SerialID.RemoveLeadingZeros();
stringLoopVal = productId + " " + serialId + ",";
stringInput = stringInput + stringLoopVal;
}
if (!stringInput.IsInitial())
{
stringHexVal.Clear();
stringHexVal = GAC_StringToHexLibrary.StringToHex(stringInput);
var ScenarioName = "BAAS";
var ServiceName = "SCPIntegration";
var HttpMethod = "POST";
var ContentType = "application/json";
var HeaderParameter : collectionof NameAndValue;
var URLParameter : collectionof NameAndValue;
var HttpResource = "";
var URLParameterEntry : NameAndValue;
var HeaderParameterEntry : NameAndValue;
HeaderParameterEntry.Name = "apikey";
HeaderParameterEntry.Value = "&BAAS_apikey&";
HeaderParameter.Add(HeaderParameterEntry);
var initialBody = "{ \"method\": \"publish\", \"params\":[\"NewSerialNumbers\", ";
var endBody = "\"] }";
Body = initialBody + "\"" + prodID + " " + invSlNo.SerialID + "\"" + "," + "\"" + stringHexVal + endBody;
var ws_result = WebServiceUtilities.ExecuteRESTService(ScenarioName, ServiceName, HttpMethod, HttpResource, URLParameter, HeaderParameter, ContentType, Body);
}
}
}
}
}
/*
Add your SAP Business ByDesign scripting language implementation for:
Business Object: ReadBlockChainData
Node: Root
Action: readData
Note:
- To access the elements of the business object node,
use path expressions, for example, this.<element name>.
- To use code completion, press CTRL+J.
- This script file is mass-enabled, i.e. the keyword "this"
refers to a collection of node instances.
*/
import ABSL;
import AP.Common.GDT;
import AP.FO.ProductDataMaintenance.Global;
import AP.LogisticsExecution.Global;
import AP.PlatinumEngineering;
var Body : DataType::LANGUAGEINDEPENDENT_EXTENDED_Text;
var prodDetails : DataType::LANGUAGEINDEPENDENT_EXTENDED_Text;
var hexString : DataType::XPEXStringType;
var manufactKey = "1XypvHi6BjzrQpgih9SEPbagRjdYj67NJ5duEr";
var resultNode : elementsof ReadBlockChainData.Result;
foreach (var rootNode in this)
{
if (rootNode.Result.Count() > 0){
rootNode.Result.Delete();
}
var ScenarioName = "BAAS";
var ServiceName = "SCPIntegration";
var HttpMethod = "POST";
var ContentType = "application/json";
var HeaderParameter : collectionof NameAndValue;
var URLParameter : collectionof NameAndValue;
var HttpResource = "";
var URLParameterEntry : NameAndValue;
var HeaderParameterEntry : NameAndValue;
HeaderParameterEntry.Name = "apikey";
HeaderParameterEntry.Value = "&BAAS_apikey&";
HeaderParameter.Add(HeaderParameterEntry);
var initialBody = "{ \"method\": \"liststreamkeyitems\", \"params\":[\"NewSerialNumbers\", ";
var endBody = "\"] }";
prodDetails = rootNode.productid.RemoveLeadingZeros() + " " + rootNode.serialnum.RemoveLeadingZeros();
Body = initialBody + "\"" + prodDetails + endBody;
var ws_result = WebServiceUtilities.ExecuteRESTService(ScenarioName, ServiceName, HttpMethod, HttpResource, URLParameter, HeaderParameter, ContentType, Body);
var json = ws_result.Content;
var i = 0;
var subString;
var publisherPattern = "(\"publishers\")";
var publisherEndPattern = "(\"],\")";
var blocktimePattern = "(\"blocktime\")";
var dataPattern = "(\"data\":\")";
var comaPattern = "(\",\")";
var startPosition = 0;
var comaPosition = 0;
var substringLength = 0;
var patternPosition = 0;
var exitLoop = 0;
while (exitLoop < 1)
{
resultNode.Clear();
// Read the Publisher
patternPosition = json.FindRegex(publisherPattern, startPosition);
if (patternPosition < 0)
{
exitLoop = 1;
}
else
{
comaPosition = json.FindRegex(publisherEndPattern, patternPosition);
if (comaPosition < 0)
{
exitLoop = 1;
}
else
{
substringLength = comaPosition - patternPosition;
subString = json.Substring(patternPosition, substringLength);
subString = subString.Replace("\"publishers\":[\"", " ");
subString = subString.Trim();
if (subString == manufactKey)
{
resultNode.publisher = "Manufacturer";
}
else
{
resultNode.publisher = "Distributor";
}
startPosition = comaPosition;
}
}
// Read the Data
patternPosition = json.FindRegex(dataPattern, startPosition);
if (patternPosition < 0)
{
exitLoop = 1;
}
else
{
comaPosition = json.FindRegex(comaPattern, patternPosition);
if (comaPosition < 0)
{
exitLoop = 1;
}
else
{
substringLength = comaPosition - patternPosition;
subString = json.Substring(patternPosition, substringLength);
subString = subString.Replace("\"data\":\"", " ");
subString = subString.Trim();
subString = subString.ToUpperCase();
var stringResult = GAC_StringToHexLibrary.HexToString(subString);
resultNode.result = stringResult;
startPosition = comaPosition;
}
}
// Read Block Time
patternPosition = json.FindRegex(blocktimePattern, startPosition);
if (patternPosition < 0)
{
exitLoop = 1;
}
else
{
substringLength = 22;
subString = json.Substring(patternPosition, substringLength);
subString = subString.Replace("\"blocktime\":", " ");
subString = subString.Trim();
resultNode.dateTime = GAC_UnixTimeLibrary.UnixTimeStampConversion(subString);
startPosition = patternPosition + 22;
}
if (exitLoop != 1)
{
rootNode.Result.Create(resultNode);
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
2 | |
2 |