Posts

Showing posts from January, 2019

UI Macro - external link in popup

<?xml version="1.0" encoding="utf-8" ?> <j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null"> <b style = "color: #DD3197" >Data Protection</b><br/> some text <a href='' onclick="event.preventDefault();gdprRef('${gs.getMessage('gdpr')}');">privacy notice</a> sets out how we process your data. <script> var myGDPRWindow; functiongdprRef(url){ if(g_form.modified){ g_form.modified=false; } var res=confirm('Do you wish to view the privacy notice?'); if (res){      myGDPRWindow=window.open(url, "s", "resizable=yes, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, copyhistory=no").blur();         //myGDPRWindow.focus(); g_form.modified=true; } }   </script> </j:jelly>

HasRolesExactly function

function gld_hasRoleExactly(role) { var au = new ArrayUtil(); var roles = gs.getSession().getRoles() + ''; var roleArray = roles.split(","); var isAuthorized = au.contains(roleArray, role); return isAuthorized; }//courtesy of https://joshneri.us/serverside-hasroleexactly-in-servicenow/

Useful Service Portal references

https://serviceportal.io community.servicenow.com Experience Homepage - Experiences (service-now.com)

getNextObjNumberPadded(); auto-numbering issues...

getNextObjNumberPadded(); was not returning the latest number but one that already existed i've managed to fix this by going to /nav_to.do?uri=sys_number_counter.do?sys_id=<as per the table in question> see my community post on the topic https://community.servicenow.com/community?id=community_question&sys_id=206dba36dbf6ef80b1b102d5ca961986

on a new record, pre-populate field values by URL

for example, raising a new call: /new_call.do? sys_id=-1 &sysparm_query= call_type=general_inquiry ^ short_description=General Enquiry

retrieve all variables - record producer or RITM - from the generated ticket

below example, i did this in a custom portal page widget. below is the server code function function getVariableValues(table, ticketNumber, optVariableName, optVariableName_db){   //--https://docs.servicenow.com/bundle/london-application-development/page/script/server-scripting/concept/c_ScriptableServiceCatalogVariables.html var gr= new GlideRecord(table);   gr.addQuery('number', ticketNumber);   gr.query();   var vars=[]; if (gr.next()) { for (var prop in gr.variables) {        if (gr.variables.hasOwnProperty(prop) ){        var variable =  gr.variables[prop].getDisplayValue();        var v = gr.variables[prop];           if(!gs.nil(v.getGlideObject().getQuestion().getLabel()) &&  !gs.nil(gr.variables[prop].getDisplayValue())) {   var label = v.getGlideObject().getQuestion().getLabel();   var variableName=v.getGlideObject().getQuestion().getName();   if (optVariableName!='' || optVariableName_db!=''){ //

Run a test load data from script calling processor

this is a modified version of the 'test load 20 records' ui action create this as a copy in the condition, add a condition to restrict it to the data source in question in this example a file import instead of having to redirect to the sys_import.do java processor, this can be done in script as follows: (instance calls itself via httprequest to access the processor, this can enable users without permissions but who can see the UI action to perform a test load on the data source with the file attached) ------------- current.update();  //--below is OOTB code, commented out but principles reused /*var redirectStr = "sys_import.do?"; // the URI redirectStr += "import_source=data_source"; // this is a Data Source import redirectStr += "&sysparm_data_source=" + current.sys_id; // the sys_id of this redirectStr += "&sysparm_tablename=" + current.import_set_table_name; // always create the same test redirectStr += &