I want to get the sys_id of the variable when GlideappVariablePoolQuestionSet(); used
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 03:24 AM
var emptyVariables = [];
var readonlyVariables = [];With this code can I get the sys_id of the particular variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 03:32 AM
Hello @Community Alums ,
Please give a try to the script below and see how it works for you.
var variableName = "your_variable_name"; // replace with the actual variable name
var variableGR = new GlideRecord('sc_variable');
variableGR.addQuery('name', variableName);
variableGR.query();
if (variableGR.next()) {
var variableSysId = variableGR.sys_id.toString();
gs.info("Sys_ID of variable " + variableName + ": " + variableSysId);
} else {
gs.info("Variable not found: " + variableName);
}
Let me know your views on this and Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 03:36 AM
@Aniket Chavan Thanks for the reply but what if more than one variable present with same name?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2024 04:20 AM
Hello @Community Alums ,
You can reference the catalog item name in the query, as each catalog item typically has unique variable names. This ensures there won't be any ambiguity or confusion, making your queries more precise and reliable.
var variableName = "your_variable_name"; // replace with the actual variable name
var catalogItemName = "your_catalog_item_name"; // replace with the actual catalog item name
var variableGR = new GlideRecord('item_option_new');
variableGR.addQuery('name', variableName);
variableGR.addQuery('cat_item.name', catalogItemName);
// Add more conditions if needed, such as 'type', 'widget', etc.
variableGR.query();
while (variableGR.next()) {
var variableSysId = variableGR.sys_id.toString();
gs.info("Sys_ID of variable " + variableName + " in catalog item " + catalogItemName + ": " + variableSysId);
}
