Business Rule

Adding the user to the group from the list field value

     vrm_spocs_to_spocGroup: function(current) {

     var group_id = gs.getProperty('sn_vdr_risk_asmt.idfc.risk.vrm.spoc_group_id');

     var spocs_ids = current.u_vrm_spocs.toString();

     var spocs = [];

     spocs = spocs_ids.split(',');

     for (var i = 0; i < spocs.length; i++) {

            var gr_member = new GlideRecord('sys_user_grmember');

            gr_member.addQuery('group', group_id.toString());

            gr_member.addQuery('user', spocs[i].toString());

            gr_member.query();

            if (gr_member.next()) {

                gs.info("User is already added to Group");

            } else {

                var add_member = new GlideRecord('sys_user_grmember');

                add_member.initialize();

                add_member.group = group_id.toString();

                add_member.user = spocs[i].toString();

                add_member.insert(); 

            }    }    },

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Update current and last financial year 

(function executeRule(current, previous /*null when async*/ ) { 

   var string = ''

    if (current.u_audit_last_report_name != '' || current.u_audit_last_report_name != null) {

        var reportDate = new GlideDateTime(current.u_audit_last_reportname.u_report_issued_date);

        var month = reportDate.getMonthUTC();

        var year = reportDate.getYearUTC();

        if (month > 3) {

            var nextYear = year + 1;

            string = year.toString() + '-' + nextYear;

        } else {

            var lastYear = year - 1;

            string = lastYear.toString() + '-' + year;

        }

        current.u_last_audited_financial_year = string;

        current.u_year_last_audit = current.u_audit_last_report_name.u_report_issued_date;

        current.u_audit_score = current.u_audit_last_report_name.u_audit_score;

    } else {

        current.u_last_audited_financial_year = '';

        current.u_year_last_audit = '';

        current.u_audit_score = '';

    }

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Allow the SOP Creator or BORM to attach the document only during the Review state and Document Pending with BORM substate

Attachment [sys_attachment]
Insert: True
table_name=sn_compliance_policy^EQ 

(function executeRule(current, previous /*null when async*/ ) {

   var tableSysId = current.table_sys_id.toString();

    var grPolicy = new GlideRecord("sn_compliance_policy");
    grPolicy.addQuery("sys_id", tableSysId);
    grPolicy.query();
    if (grPolicy.next()) {
        if (grPolicy.state.toString() == "review" && grPolicy.u_substate.toString() == "11" && (grPolicy.u_sop_creator == gs.getUserID() || grPolicy.u_sop_borm == gs.getUserID() || (grPolicy.u_sop_additional_borm.indexOf(gs.getUserID()) >= 0) || gs.hasRole("admin")) ){
            grPolicy.u_substate = "13";
            grPolicy.update();

        } else {
            gs.addErrorMessage("You can not attach document");
            current.setAbortAction(true);
        }
    }

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Set the valid Date to a future date when creating the new record

 (function executeRule(current, previous /*null when async*/ ) {

    var publishedDate = new GlideDateTime();

    publishedDate.addYearsUTC(25);

    current.valid_to = publishedDate;

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Check for logged in user and pass the value through β€œg_scratchpad” to the client side for attachment icon hide

 (function executeRule(current, previous /*null when async*/ ) {

    g_scratchpad.borm_sop = gs.getUser().isMemberOf('BORM');

    g_scratchpad.ormd_sop = gs.getUser().isMemberOf('ORMD');

    g_scratchpad.ormadmin_sop = gs.getUser().isMemberOf('ORM Admin');

    g_scratchpad.admin = gs.hasRole('admin');

})(current, previous); 

UI Policy:

Execute if true

function onCondition() {

    var _borm = g_scratchpad.borm_sop;

    var _ormadmin = g_scratchpad.ormadmin_sop;

                var _admin=g_scratchpad.admin;

    if (_borm || _ormadmin || _admin) {

        g_form.enableAttachments();

    } else {

        g_form.disableAttachments(); 

    }

} 

Execute if false

function onCondition() {

    g_form.disableAttachments(); 

}

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Insert & Update the file from the field type attachment into the attachment table

(function executeRule(current, previous /*null when async*/) {

var file = new GlideRecord("sys_attachment");

file.orderByDesc('sys_updated_on');

file.addQuery("table_sys_id", current.sys_id);

file.setLimit(1);

file.query();

if (file.next()) {

file.table_name = current.getTableName();

file.update();

}

action.SetRedirectURL(current);

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Set Short Description from details of the catalog Items variable

(function executeRule(current, previous /*null when async*/) {

current.short_description = current.variables.ppta_job_type + " - " + current.variables.department_team;

})(current, previous); 

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Trigger email notification to the previously assigned person when assigned to changes

(function executeRule(current, previous /*null when async*/) {

gs.eventQueue('problem.task.assignee',current,previous.assigned_to);

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

When mentioned field changes we need to send the email notification with the previous values



(function executeRule(current, previous /*null when async*/) {


var result = getChangedFieldNames(current);

gs.eventQueue('problem.updated.fields', current, current.assigned_to, result);

function getChangedFieldNames(gr) {

  var result = [];

  var gru = GlideScriptRecordUtil.get(current);

  var changedFieldNames1 = gru.getChangedFieldNames();

  var changedFieldNamesarray = j2js(changedFieldNames1);

  for(var i=0;i<changedFieldNamesarray.length;i++){

  var obj = {};

    obj["field"] = current[changedFieldNamesarray[i]].getLabel();

    obj["previousValue"] = previous.getDisplayValue([changedFieldNamesarray[i]]);

    obj["currentValue"] = current.getDisplayValue([changedFieldNamesarray[i]]);

    result.push(obj);

  }

return JSON.stringify(result);

}

})(current, previous);

Email Notification is the same as previous 

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Incident Duration b/w start and end date

(function executeRule(current, previous /*null when async*/) {

if (current.u_incident_start_date.nil() || current.u_incident_end.nil()) {

current.setValue('u_incident_durationn', '');

return;

}

var st = new GlideDateTime(current.u_incident_start_date);

var ed = new GlideDateTime(current.u_incident_end);

var sec = gs.dateDiff(st, ed, true);

var minutes = sec/60;

current.u_incident_durationn = parseInt(minutes,10); // Remove decimals 

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Copy attachments from the child to the parent table

When: After

Update: True

Checking for duplicate attachments before coping to parent level:

(function executeRule(current, previous /*null when async*/ ) {

    var parentRecord = new GlideRecord('x_pgpl2_spend_pre_contract');

    parentRecord.addQuery('number', current.parent.number);

    parentRecord.query();

    if (parentRecord.next()) {

        var at = new GlideRecord('sys_attachment');

        at.addQuery('table_sys_id', current.parent.sys_id);

        at.query();

        if (at.next()) {

            at.deleteMultiple();

        }

        GlideSysAttachment.copy('x_pgpl2_spend_pre_contract_task', current.sys_id, 'x_pgpl2_spend_pre_contract', parentRecord.sys_id);

    }

})(current, previous);

Without checking for duplicate attachments before coping to the parent level:

(function executeRule(current, previous /*null when async*/) {

GlideSysAttachment.copy('x_pgpl2_spend_pre_contract_task',current.sys_id,'x_pgpl2_spend_pre_contract',current.parent.sys_id);

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Copy attachments from the parent to the child table

(function executeRule(current, previous /*null when async*/ ) {

GlideSysAttachment.copy('x_pgpl2_spend_pre_contract',current.parent.sys_id,'x_pgpl2_spend_pre_contract_task',current.sys_id);

})(current, previous);

One more scenario: Here is the parent is Spend table and end users can insert attachments in any point of the tickets so we used the Attachment table to write BR so that when the user insert the attachment from portal end then attachment will be update from Spend level and when it comes to Pre-Contract Level before copy, it check for duplicate attachments.



(function executeRule(current, previous /*null when async*/ ) {

    updateTasks();

    function updateTasks() {

        var gr = new GlideRecord('x_pgpl2_spend_pre_contract');

        gr.addQuery('parent.sys_id', current.table_sys_id);

        gr.query();

        while (gr.next()) {

            var at = new GlideRecord('sys_attachment');

            at.addQuery('table_sys_id', gr.sys_id);

            at.query();

            if (at.next()) {

                at.deleteMultiple();

            }

            GlideSysAttachment.copy('x_pgpl2_spend_spend', gr.parent.sys_id, 'x_pgpl2_spend_pre_contract', gr.sys_id);

        }

    }

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Restrict Access to Policy Table based on logged-in users

(function executeRule(current, previous /*null when async*/ ) {

    var loggedInUser = gs.getUserID();

    if (gs.hasRole("admin")) {

        current.addQuery('active', true).addOrCondition('active', false);

    } else if (gs.getUser().isMemberOf('ORMD') || gs.getUser().isMemberOf('ORM Admin') || gs.getUser().isMemberOf("Compliance") || gs.getUser().isMemberOf("Legal") || gs.getUser().isMemberOf("AML KYC Compliance")) {

        current.addEncodedQuery("u_track=ORM");

    } else {

current.addEncodedQuery("u_track=ORM^u_sop_borm=" + loggedInUser + "^ORu_sop_additional_bormLIKE" + loggedInUser + "^ORu_business_unit_head=" + loggedInUser + "^ORu_sop_owner=" + loggedInUser + "^ORu_cxo=" + loggedInUser + "^ORu_sop_creator=" + loggedInUser + "^ORu_sop_dept_head=" + loggedInUser);

    } 

})(current, previous);

###################################################################################

Set Affected Locations (List Field) based on Service Offerings selected from related list


(function executeRule(current, previous /*null when async*/) {

var operation = current.operation();

var tsk = new GlideRecord('incident');

if(tsk.get(current.task)){

tsk.setWorkflow(false);//prevents other Business Rules from running

var incLoc = tsk.u_affected_territories.toString().split(','); //name of your Location field on Incident table

var soLoc = current.service_offering.location.toString();

if(operation == 'insert'){

//add Service Offering to Incident Location list if not already there

if(tsk.u_affected_territories.toString().indexOf(soLoc) == -1){

incLoc.push(soLoc);

}

}

if(operation == 'delete'){

//rebuild Service Offering Location list

incLoc = [];

var so = new GlideRecord('task_service_offering');

so.addQuery('task', current.task);

so.query();

while (so.next()) {

incLoc.push(so.service_offering.location.toString());

}

}

tsk.u_affected_territories = incLoc.join(',');

tsk.update();

}

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Copy additional comments from RITM to SCTASK

Condition: current.comments.changes()

(function executeRule(current, previous /*null when async*/) {

var sctask = new GlideRecord('sc_task');

sctask.addQuery('request_item', current.sys_id);

sctask.query();

while(sctask.next()) {

sctask.comments = current.comments.getJournalEntry(1);

sctask.update();

}

})(current, previous

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Set REQ description when the ticket is created from Order Guide

(function executeRule(current, previous /*null when async*/) {

var myNote = "";

var item = "Items Requested in Kitbag";

var gr = new GlideRecord('sc_req_item');

gr.addNotNullQuery('request');

gr.addQuery('request', current.sys_id);

gr.query();

while(gr.next()){

myNote = myNote + gr.number + " : "+ gr.cat_item.getDisplayValue() +"\n";

}

current.description = item;

current.description = current.description + "\n"+ myNote;

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Trigger notification from catalog item variable value 

(function executeRule(current, previous /*null when async*/) {

gs.eventQueue('new.finance.approval', current, current.variables.finance_lead, '');

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!



(function executeRule(current, previous /*null when async*/) {

// This concatenates all variables into a u_summary field in task table

var details = '';

      var set = new GlideappVariablePoolQuestionSet();

      set.setRequestID(current.sys_id);

      set.load();

      var vs = set.getFlatQuestions();

      for (var i=0; i < vs.size(); i++) {

      if(vs.get(i).getLabel() != '' && JSUtil.notNil(vs.get(i).getDisplayValue()) ){

     details += vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n";

}

      }


current.u_summary = details;

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Visible Field from Incident based on logged user access


(function executeRule(current, previous /*null when async*/) {

g_scratchpad.isMemberOf = gs.getUser().isMemberOf('app_sn-prod_Fulfiller-Incident Commander') || gs.getUser().isMemberOf('app_sn-prod_Fulfiller-DAZN-Management') || gs.getUser().isMemberOf('app_sn-prod-Fulfiler-DOTS-PMs');

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

When a fixture is deleted from Incident then associated service offerings should be deleted

(function executeRule(current, previous /*null when async*/) {

FixtureRemove();

function FixtureRemove()

  var incidentSysId = current.u_incident.number; //Incident number of current delected record

  var fixtureserviceoff = current.u_fixture.u_service_offering.name; //Service Offering name of current delected record

  var query = "u_incident.number=" +incidentSysId+ "^u_fixture.u_service_offering.name=" +fixtureserviceoff; 

  var fl = new GlideRecord("u_m2m_fixtures_incidents"); 

  fl.addEncodedQuery(query);

  fl.query();

  if(fl.getRowCount() == 1)

  {

   if(fixtureserviceoff != current.u_incident.service_offering.name)

    {

     var jw = new GlideRecord("task_service_offering");

     jw.addQuery("task.number", incidentSysId);

     jw.addQuery("service_offering.name", fixtureserviceoff);

     jw.query();

     while(jw.next()){

      jw.deleteRecord();  

      } 

     }

    }

 }

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Calculate Contact Term


(function executeRule(current, previous /*null when async*/) {

ContractTerm();

function ContractTerm()

{

var start = new GlideDateTime(current.starts);

var end = new GlideDateTime(current.ends);

var dur = new GlideDuration();

dur = GlideDateTime.subtract(start, end);

var days = dur.getDayPart();

var months = days/30;

var totalMonths = Math.floor(months) + ' Months';

current.u_contract_term = totalMonths;

}

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Metrics Events for Contract Table

queueMetricUpdate();

function queueMetricUpdate() {    

var gru =  new GlideScriptRecordUtil.get(current);

var fieldsChanged = gru.getChangedFieldNames();

var gr = getDefinitions(fieldsChanged);

fields = '';

while (gr.next())

fields += gr.field + ',';

if (fields.length > 0) {

fields = '[' + fields.substring(0, fields.length - 1) + ']';

gs.eventQueue('metric.update', current, fields, current.sys_mod_count, 'metric_update');

}

}

function getDefinitions(fields) {

var gr = new GlideAggregate('metric_definition');

gr.addActiveQuery();

var tables = GlideDBObjectManager.getTables(current.getTableName());

gr.addQuery('table', tables);

gr.addQuery('field', fields);

gr.groupBy('field');

gr.query();

return gr;

}

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Tag Removal from Contract


(function executeRule(current, previous /*null when async*/) {

TagRemoval(); //This business rule will remove the "Document Attached" tag from a contract record

function TagRemoval()

 var dtr = gs.getProperty("dazn.tag.document_attached");

 var gr = new GlideRecord("label_entry");  

  gr.addQuery('label', dtr);

  gr.addQuery('table_key',current.table_sys_id);

  gr.query();

   while(gr.next()){

gr.deleteRecord();

    }

}

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Calculate Vendor Tiering from multiple templates



  var total = 0,

            actual_tiering_score = 0,

            weight_cat = 0.0;

        var score_cal = new GlideRecord("asmt_metric_result");

        score_cal.addQuery("instance", current.sys_id);

        score_cal.query();

        while (score_cal.next()) {

            weight_cat = parseFloat(score_cal.metric.weight);

            total += parseInt(score_cal.getValue("actual_value")) * parseFloat(weight_cat);

        }

        actual_tiering_score = total;

        total = parseFloat(total) * parseInt(100);

        new sn_vdr_risk_asmt.INM_vrm_tiering_score().update_score(current.sys_id.toString(), parseInt(total), actual_tiering_score);

        var gr1 = new GlideRecord("sn_vdr_risk_asmt_tiering_scale");

        gr1.addQuery('applies_to', current.vdr_tiering_assessment.toString());

        gr1.query();

        while (gr1.next()) {

            if (parseInt(total) >= gr1.min && parseInt(total) <= gr1.max) {

                var gr3 = new GlideRecord("sn_vdr_risk_asmt_vdr_tiering_assessment");

                gr3.addQuery("sys_id", current.vdr_tiering_assessment.toString());

                gr3.query();

                if (gr3.next()) {

                    gr3.u_template1 = gr1.vendor_tier;

                    gr3.update();

                }

            }

}

        



(function executeRule(current, previous /*null when async*/) {

    var total=0;

    var asmt = new GlideRecord('asmt_assessment_instance');

    asmt.addQuery('vdr_tiering_assessment=' + current.vdr_tiering_assessment + '^state=complete');

    asmt.query();

    if (asmt.getRowCount() == 2) {

        while (asmt.next()) {

            total += (asmt.sn_vdr_risk_asmt_tiering_score);

        }

        var gr2 = new GlideRecord('sn_vdr_risk_asmt_tiering_scale');

        gr2.addQuery('applies_to', current.vdr_tiering_assessment.toString());

        gr2.query();

        while (gr2.next()) {

            if ((total) >= gr2.min && (total) <= gr2.max) {

                var gr3 = new GlideRecord('sn_vdr_risk_asmt_vdr_tiering_assessment');

                gr3.addQuery('sys_id', current.vdr_tiering_assessment.toString());

                gr3.query();

                if (gr3.next()) {

                    gr3.vendor_tier = gr2.vendor_tier;

                    gr3.update();

                }

            }

        }

    }

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Set the next run date using a switch statement

(function executeRule(current, previous /*null when async*/ ) { 

    switch (current.getValue("collection_frequency")) {

        case "daily":

            var date = new GlideDateTime(current.u_previously_run_date)

                                                date.addDaysUTC(1);

            current.next_run_time = (date.getDate());

            break;

        case "weekly":

            var weeklyDay = new GlideDateTime(current.u_previously_run_date)

                                                weeklyDay.addDaysUTC(7);

            current.next_run_time = (weeklyDay.getDate())

            break;

         case "monthly":

            var monthlyDay = new GlideDateTime(current.u_previously_run_date)

                                                monthlyDay.addDaysUTC(30);

            current.next_run_time = (monthlyDay.getDate())

            break;

        case "quarterly":

            var quarterlyDay = new GlideDateTime(current.u_previously_run_date)

                                                quarterlyDay.addDaysUTC(90);

            current.next_run_time = (quarterlyDay.getDate())

            break;

        case "semi_annually":

            var semiAnnualDay = new GlideDateTime(current.u_previously_run_date)

                                                semiAnnualDay.addDaysUTC(180);

            current.next_run_time = (semiAnnualDay.getDate())

            break;

        case "annually":

            var annualDay = new GlideDateTime(current.u_previously_run_date)

                                                annualDay.addDaysUTC(365);

            current.next_run_time = (annualDay.getDate())

            break;

    } 

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Get indicator details from indicator field of the indicator task without doing the Glide Query 

(function executeRule(current, previous /*null when async*/) {

var indicator = new GlideRecord('sn_grc_indicator');

                indicator.get(current.indicator);

                current.assigned_to = indicator.u_action_owner;

                current.description = indicator.short_description;

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Allow only one approver from list data type 

(function executeRule(current, previous /*null when async*/ ) { 

    // Add your code here

    if (current.approver.toString().split(',').length > 1) {

        gs.addErrorMessage("Only 1 Approver is allowed.");

        current.approver = previous.approver;

        return false;

    }

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Set next auditable year based on audit frequency 

(function executeRule(current, previous /*null when async*/ ) {

    var plan = new GlideRecord('sn_audit_advanced_plan');

    plan.addEncodedQuery('active=true^u_auditable_unit=' + current.getUniqueValue());

    plan.query();

    while (plan.next()) {

        if (current.u_audit_frequency == '2') { // once in a year

            var createdFinancialYear = plan.u_financial_year;

            var nextYear = parseInt(createdFinancialYear.slice(0, 4)) + 1;

            var adjoiningYear = parseInt(createdFinancialYear.slice(-4)) + 1;

            plan.u_next_audit_year = nextYear + '-' + adjoiningYear;

                                                plan.update();

        } else if (current.u_audit_frequency == '3') { // once in  2 years

            var createdFinancialYear = plan.u_financial_year;

            var nextYear = parseInt(createdFinancialYear.slice(0, 4)) + 2;

            var adjoiningYear = parseInt(createdFinancialYear.slice(-4)) + 2;

            plan.u_next_audit_year = nextYear + '-' + adjoiningYear;

                                                plan.update();

        } else if (current.u_audit_frequency == '4') { // once in 3 years

            var createdFinancialYear = plan.u_financial_year;

            var nextYear = parseInt(createdFinancialYear.slice(0, 4)) + 3;

            var adjoiningYear = parseInt(createdFinancialYear.slice(-4)) + 3;

            plan.u_next_audit_year = nextYear + '-' + adjoiningYear;

                                                plan.update();

        }else if (current.u_audit_frequency == '1') { // once in 6 months

            plan.u_next_audit_year = 'In 6 months';

                                                plan.update();

        }

    }

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Mandatory attachment

(function executeRule(current, previous /*null when async*/) { 

                // Add your code here

var att = new GlideRecord('sys_attachment');

    att.addQuery('table_name', 'sn_audit_engagement');

    att.addQuery('table_sys_id', current.getUniqueValue());

    att.query();

    if (!att.next()) {

        gs.addErrorMessage('Please Add the Audit Report Attachment');

        current.setAbortAction(true);

    }

})(current, previous);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!



Comments

Popular posts from this blog

Interview Questions

Exam Dumps