- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,
I am trying to get a request to auto-populate the user's assigned PC in the Configuration Item field. Still, after creating a client-callable script, a catalog client script, and a regular client script, the catalog client script did not work.
None are working. (See autopopci-1 - autopopci-3)
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @BenFan
You can try this as well.
1.Create the Catalog Client Script:
- Navigate to Service Catalog > Catalog Policy > Catalog Client Scripts.
- Click New.
- Set Name (e.g., Auto-populate Assigned PC).
- Set UI Type to All.
- Set Type to onChange.
- Set Variable set or Catalog Item accordingly, and choose the requested_for variable.
Add this sample script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var requestedFor = g_form.getValue('requested_for');// Replace 'requested_for' with your actual variable name
if (requestedFor) {
var ga = new GlideAjax('populateReqForPC');
ga.addParam('sysparm_name', 'getAssignedPC');
ga.addParam('sysparm_user_id', requestedFor);
ga.getXMLAnswer(function(response) {
if (response) {
g_form.setValue('cmdb_ci', response);
}
});
}
}
2. Create the Script Include (Server-side logic):
- Navigate to System Definition > Script Includes.
- Client Callable : checked
var populateReqForPC= Class.create();
populateReqForPC.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAssignedPC: function() {
var userId = this.getParameter('sysparm_user_id');
var gr = new GlideRecord('cmdb_ci_computer');
gr.addQuery('assigned_to', userId);
gr.query();
if (gr.next()) {
return gr.sys_id;
}
return '';
},
type: 'populateReqForPC'
});
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti