- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 06:59 AM - edited 02-11-2024 10:40 AM
I am developing a button ui action in the ritm record.
in the script i have inserted 2 variables, one takes the sys_id of a knowledge and the other takes the sys_id of a Knowledge article, which are inserted in a link that leads to the creation of a new Knowledge article assigned to the knowledge of the first variable and as parent the Knowledge article of the second variable, even if the link seems correct it only populates the field of the first sysparm_query it encounters, the second ignores it.
if i try to invert the sysparm_query it always has the same behaviour it changes the populated field.
var kb = current.variables.select_a_knowledge;
var kb_article = current.variables.knowledge_article;
action.setRedirectURL ( 'https://<istance>.service-now.com/kb_knowledge.do?sys_id=-1&sysparm_query=parent='+ kb_article +'&sysparm_query=kb_knowledge_base='+ kb +'&sys_target=kb_knowledge&sysparm_query=sys_class_name!=kb_knowledge_block&sysparm_referring_url=kb_knowledge_list.do?sysparm_query=sys_class_name%2521%253Dkb_knowledge_block%255EEQ');
My question is:
how to insert 2 sysparm_queries with 2 different sys_ids in the same url?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2024 11:40 PM - edited 02-12-2024 01:23 AM
how I solved this problem:
I changed the ui action link:
var kb = current.variables.select_a_knowledge;
var kb_article = current.variables.knowledge_article;
action.setRedirectURL ( 'https://<istance name>.service-now.com/kb_knowledge.do?sys_id=-1&sysparm_parent='+ kb_article+'&sysparm_kb='+ kb+'&sysparm_cat_item=e78d38a51b37b554e6267885464bcb98&sys_target=kb_knowledge&sysparm_query=sys_class_name!=kb_knowledge_block&sysparm_referring_url=kb_knowledge_list.do?sysparm_query=sys_class_name%2521%253Dkb_knowledge_block%255EEQ');
// in the link above I have modified the sysparms with unique names, we will need this later, here I have made them easier to read, the names after the sysparm can be of any type they are not tied to a field
sysparm_kb='+ kb
sysparm_parent='+ kb_article
sysparm_cat_item=e78d38a51b37b554e6267885464bcb98
I have made the UI action only visible when the RITM has the catalogue item with 'e78d38a51b37b554e6267885464bcb98' as an item
current.cat_item == 'e78d38a51b37b554e6267885464bcb98'
I do a test run and the link is generated correctly:
https://<istance>.service-now.com/nav_to.do?uri=%2Fkb_knowledge.do%3Fsys_id%3D-1%26sysparm_parent%3Df2765f9fc0a8011b0120ec1b352bf09b%26sysparm_kb%3D6d6c1e521bc48ad4e6267885464bcb2b%26sysparm_cat_item%3De78d38a51b37b554e6267885464bcb98%26sys_target%3Dkb_knowledge%26sysparm_query%3Dsys_class_name!%3Dkb_knowledge_block%26sysparm_referring_url%3Dkb_knowledge_list.do%3Fsysparm_query%3Dsys_class_name!%3Dkb_knowledge_block%5EEQ
but the fields are not yet populated, to do so we remain on the page that opened the UI action --> click on the hamburger menu --> configure --> Client Script
on the newly created client I put this code:
function onLoad() {
var gUrl = new GlideURL();
gUrl.setFromCurrent(); // gets the current url
var cat_item = gUrl.getParam("sysparm_cat_item"); // takes the value found in the link after the equal of sysparm_cat_item
// check that the value is equal to the sys_id of the cat_item
if(cat_item == 'e78d38a51b37b554e6267885464bcb98'){
var parent = gUrl.getParam("sysparm_parent"); //takes the value found in the link after the equal of sysparm_parent
var kb = gUrl.getParam("sysparm_kb"); //takes the value found in the link after the equal of sysparm_kb
//set values in the form
g_form.setValue('parent', parent);
g_form.setValue('kb_knowledge_base', kb);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 11:05 AM - edited 02-09-2024 11:06 AM
https://devxxxxxx.service-now.com/nav_to.do?uri=%2Fincident_list.do%3Fsysparm_query%3Dactive%3Dtrue%5Estate%3D2%26sysparm_first_row%3D1%26sysparm_view%3D
Replace the %XX values with the Ascii equivalent. Query is "active", "is", "true" AND "state", "=", "In Progress"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 11:35 AM
Hi @andreaLuongo ,
Construct url like below example,
var url ='sys_parm1';
url += 'sysparm2';
url +='sysparm3';
action.setRedirectURL(url);
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2024 10:35 AM - edited 02-11-2024 10:38 AM
hi,
I tried your suggestion, but it doesn't seem to work tell me if I set it up correctly:
var kb = current.variables.select_a_knowledge;
var kb_article = current.variables.knowledge_article;
var url ='https://<istance name>.service-now.com/kb_knowledge.do?sys_id=-1&sys_target=kb_knowledge&sysparm_query=sys_class_name!=kb_knowledge_block&sysparm_referring_url=kb_knowledge_list.do?sysparm_query=sys_class_name%2521%253Dkb_knowledge_block%255EEQ';
url += '&sysparm_query=parent='+ kb_article;
url +='&sysparm_query=kb_knowledge_base='+ kb;
action.setRedirectURL(url);
the result is:
https://<istance>.service-now.com/nav_to.do?uri=%2Fkb_knowledge.do%3Fsys_id%3D-1%26sys_target%3Dkb_knowledge%26sysparm_query%3Dsys_class_name!%3Dkb_knowledge_block%26sysparm_referring_url%3Dkb_knowledge_list.do%3Fsysparm_query%3Dsys_class_name%2521%253Dkb_knowledge_block%255EEQ%26sysparm_query%3Dparent%3Df2765f9fc0a8011b0120ec1b352bf09b%26sysparm_query%3Dkb_knowledge_base%3Daa42a4531b5eb150e6267885464bcbb5
the two sys_ids, aa42a4531b5eb150e6267885464bcbb5 and f2765f9fc0a8011b0120ec1b352bf09b are correct
set up in this way neither of the 2 fields was populated🥲
Anand Kumar can you think of why?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2024 10:56 AM - edited 02-11-2024 10:57 AM
hi,
the link generated by the code is:
https://<istance name>.service-now.com/nav_to.do?uri=%2Fkb_knowledge.do%3Fsys_id%3D-1%26sysparm_query%3Dparent%3Df2765f9fc0a8011b0120ec1b352bf09b%26sysparm_query%3Dkb_knowledge_base%3Daa42a4531b5eb150e6267885464bcbb5%26sys_target%3Dkb_knowledge%26sysparm_query%3Dsys_class_name!%3Dkb_knowledge_block%26sysparm_referring_url%3Dkb_knowledge_list.do%3Fsysparm_query%3Dsys_class_name%2521%253Dkb_knowledge_block%255EEQ
sysparm_query are:
https://<istance>.service-now.com/nav_to.do?uri=%2Fkb_knowledge.do%3Fsys_id%3D-1
// var kb_article = current.variables.knowledge_article;
%26sysparm_query%3Dparent%3Df2765f9fc0a8011b0120ec1b352bf09b
// var kb = current.variables.select_a_knowledge;
%26sysparm_query%3Dkb_knowledge_base%3Daa42a4531b5eb150e6267885464bcbb5
%26sys_target%3Dkb_knowledge%26sysparm_query%3Dsys_class_name!%3Dkb_knowledge_block%26sysparm_referring_url%3Dkb_knowledge_list.do%3Fsysparm_query%3Dsys_class_name%2521%253Dkb_knowledge_block%255EEQ
I have separated the link for easier reading😁
with this link populate the first field and ignore the second, the rest of the link I copied directly from the servicenow link when creating a new kb_knowledge.