If the short description filed contains the name of CI, the business rule will automatically enter that CI into the incidents form, can you guide me script on this we have total 472 incidents ci exist

janardhan5
Tera Contributor

If the short description filed contains the name of CI, the business rule will automatically enter that CI into the incidents form,  can you guide me script on this we have total 472 incidents CI exist.

while creating incident  we will enter CI name in short description  based on this information CI should pop on Configuration Item filed on incident form could you please guide me what script should i used in business rule

It could be great if some one help on this

Regards,

Janardhana 

1 ACCEPTED SOLUTION

Rahul Talreja
Mega Sage
Mega Sage

Hi Janardhan,

You can try below script in before insert business rule on incident table.

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

// Add your code here
gr = new GlideRecord('cmdb_ci');
gr.query();
cmdb_array = [];
while(gr.next())
    {
    var temp= gr.getDisplayValue('name');
    if(gr.getDisplayValue('name') != 'Unknown')
        {
        cmdb_array.push(temp);
        }
    }
var cmdb;
var temp2;
var desc = current.short_description;
for(i=0;i<cmdb_array.length;i++)
    {
    temp2 = desc.includes(cmdb_array[i]);
    if(temp2 == true)
        { 
        cmdb = cmdb_array[i];
        break;
        }
    }
gs.log(cmdb);
var grCmdb = new GlideRecord('cmdb_ci');
grCmdb.addQuery('name',cmdb);
grCmdb.query();
var sysId;
if(grCmdb.next())
    {
    sysId = grCmdb.getValue('sys_id');
    }
current.cmdb_ci.setValue(sysId);

})(current, previous);

Please feel free to mark my response correct if it answered your query!

Thanks and Regards,
Rahul

Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

View solution in original post

9 REPLIES 9

Ian Mildon
Tera Guru

Is the Incident creation automated or being performed manually?

If automated, the Short Description will be known to be the same every time and could be fairly easily scripted to do what you are wanting. If it is manually entered, there is no guarantee of formatting or position in the field so trying to perform scripted functions will be much harder.

Rahul Talreja
Mega Sage
Mega Sage

Hi Janardhan,

You can try below script in before insert business rule on incident table.

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

// Add your code here
gr = new GlideRecord('cmdb_ci');
gr.query();
cmdb_array = [];
while(gr.next())
    {
    var temp= gr.getDisplayValue('name');
    if(gr.getDisplayValue('name') != 'Unknown')
        {
        cmdb_array.push(temp);
        }
    }
var cmdb;
var temp2;
var desc = current.short_description;
for(i=0;i<cmdb_array.length;i++)
    {
    temp2 = desc.includes(cmdb_array[i]);
    if(temp2 == true)
        { 
        cmdb = cmdb_array[i];
        break;
        }
    }
gs.log(cmdb);
var grCmdb = new GlideRecord('cmdb_ci');
grCmdb.addQuery('name',cmdb);
grCmdb.query();
var sysId;
if(grCmdb.next())
    {
    sysId = grCmdb.getValue('sys_id');
    }
current.cmdb_ci.setValue(sysId);

})(current, previous);

Please feel free to mark my response correct if it answered your query!

Thanks and Regards,
Rahul

Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

Hi Janardhan, Is your Query resolved? Regards, Rahul
Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

suvro
Mega Sage
Mega Sage

What is the format of the Short Description ?