We have built a method to allow the helpdesk to have delegated control over the mapping between Service Contracts and Organizations. They control an Excel spreadsheet, hosted at box.net.
ServiceNow scrapes that location, loads the spreadsheet, parses the six-digit Organization IDs, and updates the contracts.
That should be good enough, but alas, it is not.
var orgID='736001'; // set orgID to the ORG where you want to synchronize user ORG records var debug=true; var orgSysID = 'declared'; var orgDSPID = 'declared'; var orgContractID = 'declared'; var gr1 = new GlideRecord('u_cmn_organization'); gr1.addQuery('u_id',orgID); gr1.query(); while ( gr1.next() ) { orgSYSID = gr1.sys_id; orgDSPID = gr1.u_dsp_group; orgContractID = gr1.u_service_contract; if (debug) { gs.log("organization sysid: "+ gr1.sys_id + " and ORG name: " + gr1.u_name + " and orgSYSID: " + orgSYSID + " and orgDSPID: " + orgDSPID + " and orgContractID: " + orgContractID); } } var gr2 = new GlideRecord('sys_user'); var memberCount = 0; var memberArray = []; gr2.addQuery('u_organization',orgSYSID); gr2.query(); while ( gr2.next() ) { memberCount += 1; memberArray.push(gr2.sys_id); if ( debug) { gs.log("members include: " + gr2.name + " and sysid: " + gr2.sys_id + " and count: " + memberCount); } var gr3 = new GlideRecord('sys_user'); gr3.addQuery('sys_id',gr2.sys_id); gr3.query(); while (gr3.next()) { gr3.u_dsp_group = orgDSPID; gr3.u_service_contract = orgContractID; gr3.update(); } }