Duplicate RIITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2024 09:36 AM
Hi
I m trying to Duplicate RITM through a botton (UI action), the user is directed to the article form with the RITM fields.
i have an issue with only a field : bli_contact which is a list Collector.
All other fileds are retrieved correctly.
Below codes:
UI action in the RITM form :
var ItemId = current.cat_item.sys_id;
var RitmId = current.number;
var url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=' + ItemId + '&sysparm_ritmId=' + RitmId ;
action.setRedirectURL(url);
Catalog Client script :
function getParmVal(name) {
var url = top.location.href;
var value = new URLSearchParams(url).get(name);
if (value)
return value;
else {
if (window !== null) {
var gUrl = new GlideURL();
gUrl.setFromCurrent();
value = gUrl.getParam(name);
return value;
}
}
return "";
}
function onLoad() {
//Type appropriate comment here, and begin script below
var parentRitm = getParmVal("sysparm_ritmId");
if (!parentRitm || parentRitm == 'undefined') {
return;
}
var ajaxcall = new GlideAjax("get_ritm_info_build");
ajaxcall.addParam('sysparm_name', 'getItem');
ajaxcall.addParam('sys_parmid', parentRitm);
ajaxcall.getXMLAnswer(ajaxResponse);
function ajaxResponse(response) {
var result = response;
//var parser = JSONParser();
result = JSON.parse(result);
g_form.setValue('BLI', result.BLI);
g_form.setValue('short_description', result.short_desc);
g_form.setValue('code_projet', result.code);
g_form.setValue('bli_contact', result.contact);
g_form.setValue('description', result.desc);
//g_form.setValue('grs_vs_content_AddCommentToRitm', parentRitm);
}
}
Script include :
var get_ritm_info_build = Class.create();
get_ritm_info_build.prototype = Object.extendsObject(AbstractAjaxProcessor, {
ajaxFunction_getItem: function() {
var result = {};
var gr = new GlideRecord('sc_req_item');
gr.addQuery('number', this.getParameter('sys_parmid'));
gr.query();
if (gr.next()) {
result['BLI'] = gr.variables.BLI + "";
result['short_desc'] = gr.variables.short_description + "";
result['code'] = gr.variables.code_projet + "";
//result['contact'] = gr.variables.bli_contact)+ ""; => not working (bli_contact is List Collector variable)
result['desc'] = gr.variables.description + "";
}
gs.log('no : ' + JSON.stringify(result));
return JSON.stringify(result);
},
type: 'get_ritm_info_build'
});
Any idea please to retrieve the fied : bli_contact
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2024 11:25 AM
Hi @Nawal
Not sure, why you copying the RITM.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-01-2024 11:39 AM
Hello @Nawal ,
Please give a try to the modified code below and let me know how it works for you.
Client Script:
function getParmVal(name) {
var url = top.location.href;
var value = new URLSearchParams(url).get(name);
if (value) {
return value;
} else {
if (window !== null) {
var gUrl = new GlideURL();
gUrl.setFromCurrent();
value = gUrl.getParam(name);
return value;
}
}
return "";
}
function onLoad() {
var parentRitm = getParmVal("sysparm_ritmId");
if (!parentRitm || parentRitm == 'undefined') {
return;
}
var ajaxcall = new GlideAjax("get_ritm_info_build");
ajaxcall.addParam('sysparm_name', 'getItem');
ajaxcall.addParam('sys_parmid', parentRitm);
ajaxcall.getXMLAnswer(ajaxResponse);
function ajaxResponse(response) {
var result = JSON.parse(response);
g_form.setValue('BLI', result.BLI);
g_form.setValue('short_description', result.short_desc);
g_form.setValue('code_projet', result.code);
// Handle List Collector field bli_contact
var bliContactField = g_form.getGlideUIElement('bli_contact');
var bliContact = bliContactField.getRefRecord();
if (bliContact.isValidRecord()) {
g_form.setValue('bli_contact', bliContact.getValue('display_value'));
}
g_form.setValue('description', result.desc);
}
}
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-02-2024 12:34 AM
Hi,
i added the code with this in the script include :
result['BLI'] = gr.variables.BLI + "";
result['short_desc'] = gr.variables.short_description + "";
result['code'] = gr.variables.code_projet + "";
result['bliContact'] = gr.variables.bli_contact;
result['desc'] = gr.variables.description + "";
but still not working 😞
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2024 04:16 AM
Can you explain your business requirement to duplicate the RITM?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader