- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2022 04:47 PM
Please see below script.
Even though I am setting values for the object, the final statement shows it is missing.
Is it correct way to set JSON object? If not then what is wrong?
var closeOutArray = [];
var closeOutObject = {
"orderCloseOut": {
"effectiveBillingDate": "",
"workCompletionDate": "",
"workOrderId": ""
}
};
gs.info('...Adding CloseOut for location ' + current.u_wo_number + ' \n');
// This shows correct value of u_wo_number
closeOutObject.orderCloseOut.effectiveBillingDate = current.u_effective_date;
closeOutObject.orderCloseOut.workCompletionDate = current.u_effective_date;
closeOutObject.orderCloseOut.workOrderId = current.u_wo_number;
closeOutArray.push(closeOutObject);
gs.info('...closeOutArray = ' + JSON.stringify(closeOutArray) + ' \n';)
// This logs ...closeOutArray = [{"orderCloseOut":{"effectiveBillingDate":{},"workCompletionDate":{},"workOrderId":{}}}]
Response will be marked helpful/correct if applicable.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2022 05:06 PM
When you use .field_name
, you get back an GlideElement, which when stringified using JSON.stringify
gives "{}"
. You can use .getValue() (or getDisplayValue()) instead to get the string value at each field, or .toString() when setting your values:
closeOutObject.orderCloseOut.effectiveBillingDate = current.getValue("u_effective_date");
closeOutObject.orderCloseOut.workCompletionDate = current.getValue("u_effective_date");
closeOutObject.orderCloseOut.workOrderId = current.getValue("u_wo_number");

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 01:18 AM
Hello,
Could you please try by converting values into string and set into the object.
closeOutObject.orderCloseOut.effectiveBillingDate = current.u_effective_date.toString();
closeOutObject.orderCloseOut.workCompletionDate = current.u_effective_date.toString();
closeOutObject.orderCloseOut.workOrderId = current.u_wo_number.toString();
closeOutArray.push(closeOutObject);
Or you can use getDisplayValue() which returns value in string format.
closeOutObject.orderCloseOut.effectiveBillingDate = current.getDisplayValue(u_effective_date);
closeOutObject.orderCloseOut.workCompletionDate = current.getDisplayValue(u_effective_date);
closeOutObject.orderCloseOut.workOrderId = current.getDisplayValue(u_wo_number);
closeOutArray.push(closeOutObject);
Kind regards,
Rajat