User Tools

Site Tools


business_rules

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

business_rules [12/30/2024 05:38] – created johnsonjohnbusiness_rules [12/31/2025 05:39] (current) – removed johnsonjohn
Line 1: Line 1:
-======Business Rules====== 
----- 
  
-=====Project Insight Update===== 
-<code> 
-// JWJ0215 10.30.24               Last tested on 10.30 @ 2.42 pm 
-// Project Insight Update Script 
-// This script will get needed data from the ServiceNow Project Request (before approved for a project), and 
-// push the data to Project Insight. 
- 
-(function executeRule(current, previous /*null when async*/ ) { 
-    var payload = {}; 
- 
-    // get user from user table 
-    var gr = new GlideRecord("sys_user"); 
-    gr.addQuery("sys_id", current.requested_for); 
-    gr.query(); 
- 
-    if (gr.next()) { 
-        payload.requested_for = gr.email.toString(); 
-    } 
-    // ***End get user*** 
-    // Get Project Insight Records from the project Insight table **U_PROJECT_INSIGHT_RECORDS** 
-    // get the sys id 
- 
-    var pigr = new GlideRecord("u_project_insight_records"); 
-    pigr.addQuery("u_requested_item", current.sys_id); 
-    pigr.query(); 
- 
-    if (pigr.next()) { 
-        payload.u_project_insight_records_sysid = pigr.sys_id.toString(); 
-        payload.u_project_insight_records_number = pigr.number.toString(); 
-        payload.u_prioritization_group = pigr.u_prioritization_group.toString(); 
-        payload.priority = pigr.priority.getDisplayValue(); 
-        payload.u_expense = pigr.u_expense.toString(); 
-        payload.u_project_request_status = pigr.u_project_request_status.toString(); 
-        payload.short_description = pigr.short_description.toString(); 
-        payload.description = pigr.description.toString(); 
-        payload.u_status = pigr.u_status.toString(); // trying u_status 
-     } 
- 
-    // Grab the Description from the task table ****************************************** 
-    gr = new GlideRecord("task"); 
-    gr.addQuery('description'); 
-    gr.query(); 
- 
-    if (gr.next()) { 
-        gr.description.toString(); 
-    } 
- 
-    gr = new GlideRecord("sys_user"); 
-    gr.addQuery("sys_id", current.variables.sponsor_manager_and_up_only_for_this_field); 
-    gr.query(); 
- 
-    if (gr.next()) { 
-        payload.sponsor_manager_and_up_only_for_this_field = gr.email.toString(); 
-    } 
- 
-    gr = new GlideRecord("sys_user"); 
-    gr.addQuery("sys_id", current.variables.contact_name); 
-    gr.query(); 
- 
-    if (gr.next()) { 
-        payload.contact_name = gr.name.toString(); 
-    } 
- 
-    // which_location_is_the_project_for 
-    gr = new GlideRecord("cmn_department"); 
-    gr.addQuery("sys_id", current.variables.which_location_is_the_project_for); 
-    gr.query(); 
- 
-    if (gr.next()) { 
-        payload.cost_center = gr.name.toString(); 
-    } 
- 
-    // ***End get Project Insight Records*** 
-    // below information is from the **SC_REQ_ITEM** table. 
- 
-    payload.sys_id = current.sys_id.toString(); 
-    payload.u_project_approved_date = current.u_project_approved_date.toString(); 
-    payload.number = current.number.toString(); 
-    payload.u_project_type = current.u_project_type.toString(); 
-    payload.request_created_on = current.variables.request_created_on.toString(); //sc_req_item   
-    payload.contact_s_phone_number = current.variables.contact_s_phone_number.toString(); //sc_req_item 
-    payload.what_is_the_problem_you_are_trying_to_solve =  
-    current.variables.what_is_the_problem_you_are_trying_to_solve.toString(); 
-    payload.u_estimated_hours = current.u_hours.toString();  // trying u_hours 
- 
-    var PI = new ProjectInsightScriptInclude(); 
-    var res = PI.send(payload); 
- 
-})(current, previous); 
- 
-//  Link 
-//  https://<instance>.service-now.com/now/nav/ui/classic/params/target/sys_script.do%3Fsys_id%3Da982dcdf87389e10fdd876a6cebb35ab%26sysparm_view%3D%26sysparm_record_target%3Dsys_script%26sysparm_record_row%3D2%26sysparm_record_list%3DORDERBYDESCsys_created_on%26sysparm_record_rows%3D6275 
-</code> 
- 
----- 
- 
-=====INCIDENT-Derive NonState Values from parent inc===== 
-<code> 
-// Condition: current.parent_incident.changes() && !current.parent_incident.nil() 
-(function executeRule(current, previous /*null when async*/) { 
- // If child incident is already Closed or Cancelled, child incident should not be updated 
- if (current.incident_state == IncidentState.CLOSED || current.incident_state == IncidentState.CANCELED) 
- return; 
- 
- // If parent incident is already Closed or Cancelled, child incident should not be updated 
- if (current.parent_incident.incident_state == IncidentState.CLOSED || current.parent_incident.incident_state == IncidentState.CANCELED) 
- return; 
- 
- // Update child incident's Category, Subcategory, Assignment group, and Assigned to fields to match that of parent incident 
- current.category = current.parent_incident.category; 
- current.subcategory = current.parent_incident.subcategory; 
- 
- // Only copy parent incident's assignment group if it is not empty. 
- if (!current.parent_incident.assignment_group.nil()) { 
- current.assigned_to = ''; 
- current.assignment_group = current.parent_incident.assignment_group; 
- } 
- 
- // Only copy parent incident's assigned to if it is not empty. 
- if (!current.parent_incident.assigned_to.nil()) { 
- current.assigned_to = current.parent_incident.assigned_to; 
- } 
- 
-})(current, previous); 
- 
-</code> 
- 
----- 
-=====INCIDENT-Display Caller Email is Empty===== 
-<code> 
-(function executeRule(current, previous /*null when async*/) { 
- 
- var callerName = current.caller_id.name; 
- gs.addInfoMessage('Please note: Email address for the caller,'+callerName+', is empty. They will not receive email communications sent by ServiceNow.'); 
- 
-})(current, previous); 
- 
-</code> 
- 
----- 
-=====True Up NonState Values from Parent INC===== 
-<code> 
-(function executeRule(current, previous /*null when async*/) { 
- 
- // Add your code here 
- var sysID = current.sys_id; 
-  
- //Check for any child incidents 
- var childCheck = new GlideRecord('incident'); 
- childCheck.addQuery('parent_incident', sysID); 
- //childCheck.addEncodedQuery('parent_incident='+sysID); 
- childCheck.query(); 
-  
- if (childCheck.hasNext()) { 
- while (childCheck.next()) { 
- // If child incident is already Closed or Cancelled, child incident should not be updated 
- if (childCheck.incident_state == IncidentState.CLOSED || childCheck.incident_state == IncidentState.CANCELED) 
- return; 
- 
- // Update child incident's Category, Subcategory, Assignment group, and Assigned to fields to match that of parent incident 
- childCheck.category = current.category; 
- childCheck.subcategory = current.subcategory; 
- 
- // Only copy parent incident's assignment group if it is not empty. 
- if (!current.assignment_group.nil()) { 
- childCheck.assigned_to = ''; 
- childCheck.assignment_group = current.assignment_group; 
- } 
- 
- // Only copy parent incident's assigned to if it is not empty. 
- if (!current.assigned_to.nil()) { 
- childCheck.assigned_to = current.assigned_to; 
- } 
-  
- childCheck.setWorkFlow(false); 
- childCheck.update(); 
- } 
- } 
- 
-})(current, previous); 
- 
-</code> 
- 
----- 
-=====Sys_USER-Add VIP Mark===== 
-<code> 
-(function executeRule(current, previous /*null when async*/) { 
- 
- //Query sys_user Table and Add VIP Mark 
- var gr = new GlideRecord('sys_user'); 
- gr.addQuery('sys_id', current.user.sys_id); 
- gr.query(); 
- 
- while (gr.next()) { 
- gr.vip = true; 
- gr.setWorkflow(false); 
- gr.update(); 
- } 
- 
-})(current, previous); 
-</code> 
- 
----- 
business_rules.1735565931.txt.gz · Last modified: by johnsonjohn

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki