Pass the values from client script to widget using spModal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,
I’m currently working on a use case where I need to display a popup message after submitting a Service Catalog form. To achieve this, I created a custom widget and added an onSubmit Catalog Client Script to invoke the widget.
Below is the catalog client script I’m using:
function onSubmit() {
// Delay needed so RITM gets created first
setTimeout(function() {
spModal.open({
widget: 'ritm_onsubmit_alert', // ✅ your widget ID
size: 'lg',
widgetInput: {
ritm: "RITM-Test-Num", //data.ritm,
submitted: "19/05/2026" //data.submitted
},
buttons: [] // remove default buttons
});
}, 2500); // ✅ IMPORTANT delay
return false;
}
As shown above, the popup appears after clicking the Submit button.
Issue:
I want to dynamically pass values such as the RITM number and submission date to the widget. However, I’m facing issues while passing these values.
I’ve tried multiple approaches, but none of them worked.
I’m also sharing both the Server Script and Client Script of the widget for reference.
Server-Side Script from widget:
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
if (input.userInput) {
gs.addErrorMessage("Input is working...");
data.ritm = input.ritm || "Loading...";
data.submitted = input.submitted || new GlideDateTime().getDisplayValue();
}else{
gs.addErrorMessage("Input is not working...")
}
})();
Client-Side Script from widget:
api.controller = function($scope, spModalInstance) {
/* widget controller */
var c = this;
c.close = function() {
spModalInstance.close();
};
};
Could someone please help me resolve this issue? Any guidance would be greatly appreciated.
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I believe the RITM number etc is generated using the OOTB SC Cat Item widget
So your widget won't know it till then
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Yes, I’m aware of that. That’s why I’m currently testing by passing hardcoded values. If I’m able to successfully pass these hardcoded values, I’ll work on implementing the dynamic part as well.
Could you please help me with how I can pass these values?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
onSubmit runs before the catalog item is actually submitted, so not possible from there
last approach as per my understanding
-> clone the OOTB "widget-sc-cat-item-v2" widget and then update the widget to capture the response after orderNow()
-> add this new widget again on your portal page
Note: I believe I shared an approach and you can take it further from here using some AI tool to generate the logic
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader