When a user submit the request, the RITM number should be autopopulated in the work notes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2022 11:24 PM
When a user submit the request, the RITM number should be autopopulated in the work notes of that change request i.e. RITMXXXXXXXX is created.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2022 01:48 AM
Hi,
You have not provided answer to my questions above and also can you share the code along with screenshot on how you have configured your BR .
Sharing screenshots and complete details will save both your and mine time as well and get you to a faster solution if possible.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2022 02:00 AM
My requirement are:
Create a UI Action “Create Request" on Change Request:
- Create a group "Change Management" , add some users & button should only be visible to the members of "Change Management" group.
- When a user click on the button, it should redirect to the catalog item "Apple iPad" on ServicePortal.
- When a user submit the request, the RITM number should be autopopulated in the work notes of that change request i.e. RITMXXXXXXXX is created.
So for that firstly I created UI action like that:
Then I use this BR script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2022 02:01 AM
So please help me to solve this problem.
regards,
Priyanka shukla
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2022 12:05 AM
Thanks for sharing the details and now I have an idea on when you want to populate work notes.
The way you are doing it right now will not work, reason being when you click on the button there is no Field or variable which holds the relationship between Change Request Table and the Requested you will be submitting , so Servicenow will not be able to identify which record it need to update which you need in work notes field.
Please follow the steps below to achieve your requirement:
1) Create a UI ACTION, what you have done is okay you just need to update the UI Action script as below:
Condition of UI Action looks good to me and you don't need a Client activity first of all in your UI Action so remove the client checkbox and just update your UI Action script as below:
var url = '/sp?id=sc_cat_item&sys_id=3f1dd0320a0a0b99000a53f7604a2ef9&sysparm_number='+ current.number;
action.setRedirectURL(url);
// Replace the catalog item sys in in above code
Now you have the Change Number in the URL which is getting redirected to your Catalog item.
2) Create a Single Line text Variable and say name it as "Change Number" on your Catalog Item.
3) Create a On Load Catalog Client Script on your Catalog Item and use the script as below. This script will help you auto populate the Change number from where you hae clicked and got redirected to the Catalog form and will help you to identify the change number which need to be updated once the request is submitted.
On Load Catalog Client Script:
function onLoad() {
//Use the 'getParameterValue' function below to get the parameter values from the URL
var num = getParameterValue('sysparm_number');
if (num) {
g_form.setValue('Variable Name', num); // Replace "Variable Name" with new variable which you have created and will store your Change number fetched from URL
}
}
function getParameterValue(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(top.location);
if (results == null) {
return "";
} else {
return unescape(results[1]);
}
}
Sample Screenshot for reference on how your Catalog Client script will look like:
Make sure to select UI Type to Run as All in your Catalog client script as shown below:
If you do not need to show this variable then you may hide it as well using a UI Policy, but first don't hide it and test the functionality you need and later once everything works then hide it.
4) Now you need to write a After Insert Business Rule on Requested Item Table and use the details below for the BR:
BR Details:
Table Name: Requested Item
When: After Insert
Condition: Item is Give the Name of your Catalog Item(This will ensure this BR does not gets trigger for all items unnecessary)
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here\
var getChangeNumber = current.variables.VariableName; // Replace "VariableName" with the new CHange number variable you have created in step above
var gr = new GlideRecord('change_request');
gr.addQuery('number', getChangeNumber);
gr.query();
if(gr.next()) {
gr.work_notes = current.number + ' is created';
gr.update();
}
})(current, previous);
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke