- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2024 11:58 PM
Hello,
I currently have a transform map that I used to load data in ServiceNow. I now have a requirement get the rows of the loaded data and convert into a JSON string so I can store that into a field in ServiceNow.
This is the sample data:
| number | short description | state | created |
| INC1089756 | sample record | new | 4/24/2024 |
I want to convert this to a JSON string that looks like this one:
{number: "INC1089756", short_description: "sample record", state: "state", created: "4/24/2024"}
And save the JSON string to a new field. Is this possible?
Appreciate all the help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 01:39 AM - edited 04-24-2024 01:40 AM
Hi @Evren Yamin ,
A small little change here please make it OnAfter Script instead of onComplete script
Result
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 02:05 AM - edited 04-24-2024 02:07 AM
You can use this script in the transform script or business rule.
This script is generic for all the fields. If you want to ignore the system fields, put an if condition.
Example:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 01:31 AM - edited 04-24-2024 01:32 AM
Hi @Evren Yamin ,
I tried your problem in my PDI and it works for me.
Please create onComplete transform map script and add below code
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
gs.log('Incide ON Complete script = ' + source.u_number);
var JsonData = {
number: source.getValue('u_number'),
short_description: source.getValue('u_short_description')
};
var jsonToString = JSON.stringify(JsonData);
gs.log("jsonToString = " + jsonToString);
target.description = jsonToString;
target.update();
})(source, map, log, target);
Image for reference
Result
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 01:39 AM - edited 04-24-2024 01:40 AM
Hi @Evren Yamin ,
A small little change here please make it OnAfter Script instead of onComplete script
Result
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2024 12:39 AM
Hello @Community Alums, I am now able to do this. Thanks so much for your help 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2024 02:11 AM
@Community Alums Good Effort 👏
