How to Pass the Value from Widget Controller to On-load Script to set it to Variable field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
I am trying to create a spModal + Widget.
Where if I click Submit, it will pass the value from controller into on-load script to set it to the variable field.
HTML code:
<div>
<label>Select Mailbox Type</label>
<select ng-model="c.selected">
<option value="(On-Prem)">CUI User (On-Prem)</option>
<option value="O365">Non-CUI User (O365)</option>
</select>
<br><br>
<button class="btn btn-primary" ng-click="c.submit()">Submit</button>
</div>
Controller:
api.controller = function() {
var c = this;
c.selected = '';
c.submit = function() {
if (!c.selected) {
alert('Please select a value');
return;
}
alert(c.selected);
c.close(c.selected); // ✅ pass string back
};
};
Onload:
function onLoad() {
var cui_value = g_form.getValue('cui_mailbox_location');
spModal.open({
widget: 'widget_variable',
backdrop: 'static',
buttons: [],
}).then(function(result) {
alert(result);
if (result) {
setTimeout(function() {
g_form.setValue('cui_mailbox_location', result);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi @Jeck Manalo ,
Try adding a console.log(result) or alert(result) inside the callback to confirm the value is being returned from the widget:
try this
function onLoad() {
spModal.open({
widget: 'widget_variable',
backdrop: 'static',
buttons: []
}).then(function(result) {
if (result) {
g_form.setValue('cui_mailbox_location', result);
console.log('Selected Value: ' + result);
}
});
}
Catalog Client Script (onLoad)
function onLoad() {
spModal.open({
widget: 'widget_variable',
backdrop: 'static',
buttons: []
}).then(function(result) {
if (result) {
g_form.setValue('cui_mailbox_location', result);
console.log('Selected Value: ' + result);
}
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
i just figure out that the result in onload is the OK button in spModal. which cause to {object} {object} value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
32m ago
Hello @Jeck Manalo ,
Try console.log(JSON.stringify(result)) and see whats actual value getting there .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
what's your actual business requirement here?
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader