Wednesday, September 16, 2020

Important ServiceNow Script or Reference

 ServiceNow Best Practice :





Attachment script Attachment Mandatory --- 




function onSubmit() {

    if (g_form.getValue('non_tracked_devices') == 'Yes') {
        var cat_id = g_form.getValue('sysparm_item_guid');
        var gr = new GlideRecord("sys_attachment");
        gr.addQuery("table_name", "sc_cart_item");
        gr.addQuery("table_sys_id", cat_id);
        gr.query();
        if (!gr.next()) {
            alert("You must add an attachment before submitting this request.");
            return false;
        }
    }

}

//Script to Delete multiple record 

var psc = new GlideRecord('<table_name>'); //Make sure table name is correct
psc.addEncodedQuery('sourceISNOTEMPTY');// Encoded Query or Filter if any required 
psc.addQuery('sourceISNOTEMPTY');//Query or Filter if any required 
psc.setLimit('10'); //Limit number of records 
psc.setWorkflow(false); //Turn off business rule or notifications
psc.deleteMultiple();



//On Change Client script Example ...   Disable or Enable the form 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue == '') {
      return;
   }
    var u1 = g_form.getValue('sitescope_manager'); //optional
g_form.addInfoMessage('Please wait while fetching Server Name');
g_form.getFormElement().disable();
var links = g_form.getFormElement().getElementsByTagName("a");
for ( i=0;i<links.length;i++)
{
links[i].hide();
}
var ga = new GlideAjax('Sitescope');
ga.addParam('sysparm_name','sitescope'); 
ga.addParam('sysparm_sitescope_manager',u1); //optional
ga.getXML(FolderFetch);
}
function FolderFetch(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer == "start")
{
g_form.showFieldMsg('remote_server_name','There is some Congestion in the Network. Please try again Later','error');
}
else
{
var outputval=answer;
var arr=outputval.split("\n");
var k=0;
while(k!=arr.length)
{
g_form.addOption('remote_server_name', arr[k],arr[k]);
k++;
}
}
g_form.clearMessages();
g_form.getFormElement().enable();
var links1 = g_form.getFormElement().getElementsByTagName("a");
for ( i=0;i<links1.length;i++)
{
links1[i].show();
}
}

   //How to setup OAuth2 authentication for RESTMessageV2 integrations



//Find Duplicate record in table with filed value :

var dupRecords = [];
var gaDupCheck1 = new GlideAggregate('cmdb_ci_hardware');
gaDupCheck1.addAggregate('COUNT', 'serial_number');
gaDupCheck1.groupBy('serial_number');
gaDupCheck1.addHaving('COUNT', '>', 1);
gaDupCheck1.query();
while (gaDupCheck1.next()) {
    dupRecords.push(gaDupCheck1.serial_number.toString());
}
gs.print(dupRecords);


//Script to delete duplicate records: 


var dup = new GlideAggregate('dscy_router_interface');
dup.groupBy('mac_address');
dup.query();
while(dup.next()) {
var dup1 = new GlideRecord('dscy_router_interface');
dup1.addQuery('mac_address', dup.mac_address);
dup1.query();
dup1.next();
while(dup1.next())
dup1.deleteRecord();
}


//CI Asset Synchronization useful scripts 

var serialNum = [”SE415WS47”, ”VMware-42 26 87 93 04 f8 e6 15-9c 43 e6 c2 0e 76 4f 55”,];
for (var i = 0; i < serialNum.length; i++) {
    var grCI = new GlideRecord("cmdb_ci_hardware");
    grCI.addEncodedQuery('sys_class_name=cmdb_ci_computer');
    grCI.addQuery("discovery_source", "MS SMS");
    grCI.addQuery("serial_number", serialNum[i]);
    grCI.query();
    while (grCI.next()) {
        var grAlm = new GlideRecord("alm_hardware");
        grAlm.addQuery("serial_number", serialNum[i]);
        grAlm.query();
        while (grAlm.next()) {
            grAlm.ci = grCI.sys_id.toString();
            grAlm.setWorkflow(false);
            grAlm.update();
        }

    }
}

var serialNum = ["1N44FW2", "1PR8YW2", "1QDKGP2"];
for (var i = 0; i < serialNum.length; i++) {
var grCI = new GlideRecord("cmdb_ci_hardware");
grCI.addEncodedQuery('sys_class_name=cmdb_ci_computer');
grCI.addQuery("discovery_source", "NULL");
grCI.addQuery("serial_number",serialNum[i]);
grCI.query();
while (grCI.next()) {

    var grCI1 = new GlideRecord("cmdb_ci_hardware");
    grCI1.addEncodedQuery('sys_class_name=cmdb_ci_computer');
    grCI1.addQuery("discovery_source", "MS SMS");
    grCI1.addQuery("serial_number", serialNum[i]);
    grCI1.query();
    while (grCI1.next()) {
        grCI1.asset = grCI.asset;
        grCI1.update();

    }
}
}


// Manually Create record in windows Server or any other class using script 

var payload = {
   "items": [
      {
         "className": "u_cmdb_ci_mongoose_web_server",
         "lookup": [],
         "values": {
            "name": "Mongoose@owa-sd-01",            
            "version": “5.5”,
            "running_process_command": "c:\\clouddimensions\\mongoose.exe",
            "sys_class_name": "u_cmdb_ci_mongoose_web_server"
         }
      },
      {
         "className": "cmdb_ci_win_server",
         "lookup": [],
         "values": {
            "name": "OWA-SD-01"
         }
      }
   ],
   "relations": [
      {
         "type": "Runs on::Runs",
         "parent": 0,
         "child": 1
      }
   ]
};

var jsonUtil = new JSON();
var input = jsonUtil.encode(payload);
var output = SNC.IdentificationEngineScriptableApi.createOrUpdateCI(‘ServiceNow’, input);
gs.print(output);


//Azure Fundamental :   -



Remove Middle name from a name in Excel Sheet .

Using formula may be a very easy way for most of Excel users.

Select a blank cell next to the name list, and type this formula =TRIM(LEFT(A1,FIND(" ",LOWER(A1),1))) & " " & TRIM(MID(A1,FIND(" ",LOWER(A1),FIND(" ",LOWER(A1),1)+1)+1,LEN(A1)-FIND(" ",LOWER(A1),1)+1)) into it, then press Enter button on the keyboard and drag the Auto Fill handle to fill the range needed to apply the formula. Now you can see all the name of the list are shown in the new column without middle initials.

// Get all the incidents updated 3 days before

var dupRecords = [];
var count = '';
var gr = new GlideRecord('incident');
gr.addQuery('sys_updated_onRELATIVEGE@dayofweek@ago@3');
gr.query();
while(gr.next()){
dupRecords.push(gr.number);
}
gs.print(dupRecords);

   

1 comment:

  1. She is a passionate sweeper, with tens of 1000's of dollars worth of prize wins to her name, and she has been sharing advice about method to|tips on how to} be a winner for over a decade. Erving Goffman, the legendary social psychologist who quickly as} worked as a blackjack supplier in Vegas, dismissed them as not being a correct "sociological entity" – in any case, there wasn't a lot social interaction at work. Anthropologist Clifford Geertz called slots "stupid mechanical cranks", of curiosity solely to "women, youngsters, adolescents… the extremely poor, the socially despised, and the personally idiosyncratic". I have have} intercepted Schüll, on her way to educate a doctoral seminar at Columbia University, to stroll me by way of Resorts World on line casino in Queens, New York. Driving down Rockaway Boulevard, past pawn outlets, I enter the on line casino driveway, ascend the multistorey car park and a few quick steps later am on the ground. The 우리카지노 likelihood for the Shop to be restocked increases as extra cash are inserted.

    ReplyDelete