Using variables in script to create Json - Newbie help
Posted: Thu Dec 21, 2017 3:14 am
Pretty new to the scripting module but we are trying to pull variables from an XML document then create a json inside a script (it needs to authenticate before pushing into the API)
So dropping the XML into a folder and using XML pickup with Metadata as asset.
My understanding is that this should save this data to the job which I should then be able to pull into my script? or do I require another step to save the data under a simple field before using the variables in my script?
I want to change out the fixed values I have for variables in the below section of script:
//construct the json
var json = '{"Orders": [ {"UniqueSubmitOrderID": "string","Status": { "Value": 0, "EnumType": "confirmed" },"InvoiceCustomer": { "Code": ' + Address addressID + ',"Contact": ' + Name + ', "ContactEmail": "invoice@email.com", }, "DeliveryCustomer": {"Name": "test customer","Address": { "AddressLines": ["123 Main St","Address Line 2"],"City": "Grenada North", "Region": "Wellington", "Country": "New Zealand","Postcode": "1234","Telephone": "04 472 3042",} "Contact": "Cades test","ContactEmail": "invoice@email.com",},"RequiredDate": "2017-12-28T22:13:03.613Z","OrderDate": "2017-12-28T22:13:03.613Z","Ref1": "PO5555","Items": [{"StockItemID": 12018,"Quantity": 1,}]}]}';
//store the json as a file that can be POSTed to the API
var filename=s.createPathWithName(job.getNameProper()+"_uploadattachment.json");
var textFile = new File(filename);
textFile.open(File.WriteOnly);
textFile.write(json);
textFile.close();
Anyone able to help point me in the right direction?
So dropping the XML into a folder and using XML pickup with Metadata as asset.
My understanding is that this should save this data to the job which I should then be able to pull into my script? or do I require another step to save the data under a simple field before using the variables in my script?
I want to change out the fixed values I have for variables in the below section of script:
//construct the json
var json = '{"Orders": [ {"UniqueSubmitOrderID": "string","Status": { "Value": 0, "EnumType": "confirmed" },"InvoiceCustomer": { "Code": ' + Address addressID + ',"Contact": ' + Name + ', "ContactEmail": "invoice@email.com", }, "DeliveryCustomer": {"Name": "test customer","Address": { "AddressLines": ["123 Main St","Address Line 2"],"City": "Grenada North", "Region": "Wellington", "Country": "New Zealand","Postcode": "1234","Telephone": "04 472 3042",} "Contact": "Cades test","ContactEmail": "invoice@email.com",},"RequiredDate": "2017-12-28T22:13:03.613Z","OrderDate": "2017-12-28T22:13:03.613Z","Ref1": "PO5555","Items": [{"StockItemID": 12018,"Quantity": 1,}]}]}';
//store the json as a file that can be POSTed to the API
var filename=s.createPathWithName(job.getNameProper()+"_uploadattachment.json");
var textFile = new File(filename);
textFile.open(File.WriteOnly);
textFile.write(json);
textFile.close();
Anyone able to help point me in the right direction?