- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 01:35 AM
Hi,
I have written a script action which is called from the script include via gs.eventQueue {
} method.
I am trying to update the state from the request data but for some reason the state is not updating
This is my script action:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 03:02 AM
@tanz oh okay if this is the format what you wrote is correct .Can you replace it with below script and try once
var parsedData = JSON.parse(event.parm1);
var txId = parsedData[0].MessageBody.u_tx_id;
var st = parsedData[0].MessageBody.state;
var grTx = new GlideRecord('x_tool');
grTx.addQuery('u_tx_id', txId);
grTx.addActiveQuery();
grTx.setLimit(1);
grTx.query();
if (grTx.next()) {
if (st!="") {
var grState = new GlideRecord('sys_choice');
grState.addQuery('name', 'x_tool');
grState.addQuery('element', 'state');
grState.addQuery('label', st);
grState.query();
if (grState.next()) {
grTx.state = grState.value;
grTx.update();
} else {
gs.info('State not present');
}
}
}
Hope this helps
Mark the answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 01:41 AM
Hello @tanz ,
if your JSON is not stored in an array no need to access it like [0] for accessing first element
replace like below
Just make sure before send the JSON as a event parm1 use JSON.stringify(your_json)
And then access it like below
Hope this helps
Mark the answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 02:53 AM
This is the JSON which is storing in parm 1 of the event from the event logs:
[{"MessageBody":{"u_tx_id":"MP0001222","state":"Completed"},"data_topic":"test"}]
But stil the state is not updating
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 03:02 AM
@tanz oh okay if this is the format what you wrote is correct .Can you replace it with below script and try once
var parsedData = JSON.parse(event.parm1);
var txId = parsedData[0].MessageBody.u_tx_id;
var st = parsedData[0].MessageBody.state;
var grTx = new GlideRecord('x_tool');
grTx.addQuery('u_tx_id', txId);
grTx.addActiveQuery();
grTx.setLimit(1);
grTx.query();
if (grTx.next()) {
if (st!="") {
var grState = new GlideRecord('sys_choice');
grState.addQuery('name', 'x_tool');
grState.addQuery('element', 'state');
grState.addQuery('label', st);
grState.query();
if (grState.next()) {
grTx.state = grState.value;
grTx.update();
} else {
gs.info('State not present');
}
}
}
Hope this helps
Mark the answer correct if this helps you
Thanks