Skip to main content

Known issue - clear variable value on ui policy action not working

 variables may still be populated on the generated RITM! Need to check with ServiceNow if this is a known issue > UPDATE: you need to tick the run on RITM and task checkboxes, as well as the cat item

However, another issue occurs whereby variables are blanked when you add to the cart. Referred this back to ServiceNow who came back with this update:

So in order to fix the issue we need to create duplicate UI policy where we need to select "clear the variable value" set to "false" and uncheck the "on load" option from the UI policy. 6. Another UI policy where "clear the variable value" set to "true" and check the "on load" option from the UI policy.

 

====

workaround - uncheck the 'clear variable value' flags (so it also works when adding item to the cart as opposed straight checkout)

onSubmit client script code:

(g_form.isVisible only works in SP)

//--Pop this into an onSubmit client script – must use setValue “” (clearValue doesn’t seem to work) //--loop through variables--as the ui policy action 'clear variable value' not working on the generated RITM
var emptyVariables = []; var populatedVariables = []; if (typeof spModal != 'undefined') { //--loaded from Service Portal var allFields = g_form.getFieldNames(); for (var fieldName in allFields) { var fieldLabel = allFields[fieldName]; var fieldVal_p = g_form.getValue(fieldLabel).toString(); if (fieldVal_p == '' || g_form.isVisible(fieldLabel) == false) { if (fieldVal_p != 'false') { //emptyVariables.push(fieldLabel+': ' + fieldVal_p); g_form.setValue(fieldLabel, ''); } } else { //populatedVariables.push(fieldLabel+': ' + fieldVal_p); } } //alert('emptyVariables: ' + emptyVariables.toString()); //alert('populatedVariables: ' + populatedVariables.toString()); //return false;//--testing only } else { var sRT = g_form.getValue('sn_request_type');
if (sRT != 'Update') { g_form.setValue('sn_group_type_to_update', ''); } if (sRT != "Deactivate") { g_form.setValue('sn_group_type_to_deactivate', ''); } var allVariables = document.getElementById('variable_map').getElementsByTagName('item'); for (var i = 0; i < allVariables.length; i++) { try { var item = allVariables[i]; var itemName = item.getAttribute('qname').toString(); //alert(item.id); var item_el = document.getElementById(g_form.resolveNameMap(itemName)); //alert(itemName + ' ' + window.getComputedStyle(item_el).display); var iWidth = (item_el.offsetWidth); var iHeight = (item_el.offsetHeight); var bProceed = true; if (sRT == 'Deactivate' && itemName == 'sn_group_to_deactivate') { bProceed = false; } if (sRT == 'Update' && itemName == 'sn_group_type_to_update') { bProceed = false; //--do not blank visible reference fields } if (bProceed && iWidth == 0 && iHeight == 0 && g_form.getValue(itemName) != 'true') {//--do not blank checkbox //alert("blanking item " + itemName); g_form.setValue(itemName, ''); } } catch (ex) { } }
}
}

Comments

Popular posts from this blog

ServiceNow check for null or nil or empty (or not)

Haven't tested these all recently within global/local scopes, so feel free to have a play! option 1 use an encoded query embedded in the GlideRecord , e.g.  var grProf = new GlideRecord ( 'x_cls_clear_skye_i_profile' ); grProf . addQuery ( 'status=1^ owner=NULL ' ); grProf . query (); even better use the glideRecord  addNotNullQuery or addNullQuery option 2 JSUtil.nil / notNil (this might be the most powerful. See this link ) example: if ( current . operation () == 'insert' && JSUtil . notNil ( current . parent ) && ! current . work_effort . nil ())  option 3 there might be times when you need to get inside the GlideRecord and perform the check there, for example if the code goes down 2 optional routes depending on null / not null can use gs.nil : var grAppr = new GlideRecord ( 'sysapproval_approver' ); var grUser = new GlideRecord ( 'sys_user' ); if ( grUser . get ( 'sys_id' , current . approver )){...

Code a pause/wait - gs.sleep or gs.wait alternative, pause script for specified seconds (timer)

Code a pause/wait - gs.sleep / gs.wait alternative, pause script for specified seconds (timer)  e.g. 10 seconds: do_sleep ( 10000 ); function do_sleep ( milliseconds ) { var start = new Date (). getTime (); for ( var i = 0 ; i < 1e7 ; i ++) { if (( new Date (). getTime () - start ) > milliseconds ){ gs . print ( 'waking up!' ); break ; } } }