How to retrieve value from RITM dynamically if user is passing value in a query format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2023 05:50 AM
Hi All,
Scenario:
From flow designer as a input user will pass some query to retrieve data on RITM table and update it on Short Description on RITM Table.
Eg: User has passed : current.cat_item.name;
So it should run on RITM Table, and update the catalog item name in short description of RITM Table.
I have written script:
var a = "current.cat_item.name";
var b = a.split('.');
for (var i = 0; i < b.length; i++) {
this["b"+i] = b[i];
}
gs.info(b1);
gs.info(b2);
var gr = new GlideRecord('sc_req_item');
gr.get('6ef4c4ef1b48bd54366ea7953b4bcb23');
gs.info(gr[b1][b2]);
It is giving correct Output. But My requirement is how to make it Generic.
For this case we know, that we have length till 2nd position, so we given gr[b1][b2].
But what if user has given more than this.
So pls help me in making this Generic. Like gr[a1]....gr[an-1].
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2023 07:17 AM
I am not 100% sure what you are trying to achieve. Dot retrieve dot-walked paths of various depth, you can simple use getElement (e.g. gr.getElement("very.long.dot.walking.path").toString()) to retrieve the value.
Also note that you can display static dot-walked paths without having to code by using the "Auto-populate" feature of catalog variables.
Can you show with screenshots what you currently have and what exactly you are trying to accomplish. The current description leaves too much room for interpretation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2023 07:37 AM
In my case the user is sending the input in json like this {"short_description":"current.variables.variable_name.display_value"};
That is why I am converting it to array and fetching value.
If I will pass it like this, gr.getElement("current.variables.variable_name.display_value"), it will return null.
but,
if I will pass this
gr.getElement("variables.variable_name.display_value"), then it will return correct value.
But how to exclude current and return the remaining content.
Pls Help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2023 08:30 AM
The following code should do the job:
var variablePath = "current.variables.variable_name.display_value";
gs.info(gr.getElement(variablePath.substring(variablePath.indexOf(".") + 1)).toString());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2023 07:32 AM
Hi,
I hope you are only doing this for some kind of test. Injecting code is a really bad idea and you would need a lot of code to secure the input data before allowing it to be used for anything.
With that said, you are dynamically collecting the data with your for loop after the split. The same way you need to have another loop when using it. Then it doesn't matter how many "entries" there are in the field.
Regards,
Niklas