Unable to pass values from form values to g_model.setframe record using ui action on the workspace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
So my requirement is for Service operation workspace, when user clicks on a button on sc_task table, that should prompt for serial number or asset tag, if any of matching asset found system should show it in model pop up and pass sc_task related requested_for field to the assed_to field of asset record which is in the model popup. I have developed the logic that able to pull the matching asset record but could able to succeed in passing value from sc_task client side to the model record field.
I have configured the onLoad client script and tried to read the url parameter, this does not make any difference. The above code is able to show the popup on the sc_task record.
Please help me if incase of any thoughts/correction here. Thank you in adavance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
function onClick(g_form) {
// Prompt user for asset tag
g_modal.showFields({
title: "Enter Asset ID/Serial Number",
fields: [{
type: 'string',
name: 'asset_tag',
label: getMessage('Asset Tag/Serial Number'),
mandatory: true
}],
size: 'lg'
}).then(function(fieldValues) {
//alert(g_form.getValue('assigned_to'));
var assignedTo = g_form.getValue('assigned_to'); // sc_task field
var taskSysId = g_form.getUniqueValue(); // sc_task sys_id
var taskNumber = g_form.getValue('number'); // sc_task number
openAsset(fieldValues.updatedFields[0].value, assignedTo);
// var assetTag = fieldValues.updatedFields[0].value;
});
function openAsset(tag, assignedTo) {
//alert(assignedTo);
var assetTag = tag;
//prompt('Enter Asset Tag:');
if (!assetTag) {
alert("you didn't enter a value!");
return; // User canceled
} else {
// Use GlideAjax to validate asset tag
var ga = new GlideAjax('AssetTagValidator');
ga.addParam('sysparm_name', 'getAssetSysId');
ga.addParam('sysparm_asset_tag', assetTag);
ga.getXML(function(response) {
var resul = response.responseXML.documentElement.getAttribute('answer');
//alert(result);
var resul1 = resul.split(',');
var result = resul1[0];
var ci = resul1[1];
if (result.startsWith('ERROR:')) {
// Show error message
g_form.addErrorMessage(result);
} else {
var sysId = result;
if (!sysId || sysId === '') {
alert('Invalid sys_id returned for asset.');
return;
}
//+ '&sysparm_assigned_to=' + encodeURIComponent(assignedTo)
var url = '/alm_asset.do?sys_id=' + sysId ;
alert('url is '+url);
var modal = g_modal.showFrame({
title: 'Update Asset',
// url: '/alm_asset.do?sys_id=' + sysId+'&assigned_to= ${assignedTo}',
url: url, // Encode for safety
size: 'lg',
height: 10000
});
modal.setPreference('assigned_to', assignedTo);
g_form.setValue('cmdb_ci', ci);
// size: 'lg',
// Optional: Refresh the parent form after modal closes
modal.on('close', function() {
g_form.refresh();
});
}
});
}
}
}
