The CreatorCon Call for Content is officially open! Get started here.

Discovery Pattern Extension change date format from YYYY-MM-DD to DD-MM-YYYY

Owais3
Tera Expert

Hello all,

 

I've extended a windows os - servers pattern to pull the InstallDate from a server; I'm not using a custom field but using the ootb install_date field that is avaiable on the form.

 

I've managed to get part of it working but my install_date field does not populate with the date on the ci.


My WMI Query is set like this:

1.png

And for the Parse Variable the settings are set to this:

2.png

 

This is the output:

3.png

 

I believe it's not setting the date on the install_date field on the ci because the ci install_date format is in DD-MM-YYYY HH:MM and not YYYYMMDD like above.

 

Any idea how I can convert this to DD-MM-YYYY and set it on the install_date field on the ci upon discovery.

 

I was pointed towards 'Set Parameter Value' step and use EVAL( as shown below:

Owais3_0-1676553027404.png

 

But not entirely sure what to put in here to pull the variable from the step before and convert the date and then set it as well.

Owais3_1-1676553106055.png

 

Any suggestions or any idea how I can get this fully working would be much appriciated.

Thank you

1 ACCEPTED SOLUTION

doug_schulze
ServiceNow Employee
ServiceNow Employee

Make your life easier by just running the system info command and parse the value from that.  

 

doug_schulze_0-1678908062089.png

 

View solution in original post

14 REPLIES 14

Hi @SiD2 

 

You mentioned referring to your example script, where can I find this or did you mean the OOB "Linux\Unix OS - Pre Sensor" pre sensor script.

 

If not are you able to share the example script.

Thank you

SiD2
ServiceNow Employee
ServiceNow Employee

Hi @Owais3 

 

Yes, I meant the OOB script as example "Linux\Unix OS - Pre Sensor".

 

Please mark Helpful / Accept Solution so that it helps others with similar questions.

Hi @SiD2 

 

Thanks again.

So I had a look at the script and it's pretty much the same as what I posted, I've updated mine a little as shown below:

/*
 *  1. Pre sensor:  You can change payload before it will be proccesed by Identification Engine.
 *	  Use IEJsonUtility in order to add relevant information to the payload
 *     Input parameters in Pre sensor mode: payload, patternId
 *  2. Post sensor: You can update/add missing info to the DB based on result (Json) from
 *     Identification Engine
 *     Output parameters in Post sensor mode: payload
 *
 */
var rtrn = {};

//parsing the json string to a json object
var payloadObj = JSON.parse(payload);
var discoveredServer = cmdb_ci_win_server;

var handleOSInstallDate = function() {
    try {
        var iddate = discoveredServer.install_date;
        if (iddate) {
            var intiddate = parseInt(iddate);
            var gdt = new GlideDateTime();

            gdt.setNumericValue(iddate);
            discoveredServer.install_date = gdt.getDisplayValueInternal();
        }

    } catch (e) {
        gs.error(e);
    }


};

if (Ci.extendsFromTable(payloadObj.items[0].className, 'cmdb_ci_computer')) {
    discoveredServer = payloadObj.items[0].values;
}

if (discoveredServer) {
    handleOSInstallDate();
}

rtrn = {
    'status': {
        'message': 'OS - Windows OS - Pre Sensor script finished successfuly',
        'isSuccess': true
    },
    'patternId': patternId,
    'payload': JSON.stringify(payloadObj)
};

 

When I run discovery, I get the following error.

 

Owais3_0-1678378895084.png

 

Are you able to guide me further in retrieving the results.

Thanks

SiD2
ServiceNow Employee
ServiceNow Employee

Hi @Owais3 

 

Not sure I could trace such from this example but you need to put some gs.info logs in above script in multiple places to see where we are trying to access on null object and take it further.

 

Please mark Helpful / Accept Solution so that it helps others with similar questions.

doug_schulze
ServiceNow Employee
ServiceNow Employee

Make your life easier by just running the system info command and parse the value from that.  

 

doug_schulze_0-1678908062089.png