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

janardhan5
Tera Contributor

some one posted and removed this one ..its working fine for me thanks for the great help who posted this script 

 

 

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);

Rahul Talreja
Mega Sage
Mega Sage
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);


Welcome Janardhan!

Good to know it helped you!

Happy to help:)

Can you please mark my answer correct so this thread can be closed, which will help future visitors!!

Thanks in Advance

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

can you please tell me where to enter this scrip ? 

Hi Karan, You an wirte it in insert update advance business rule. Thanks
Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

Hi Janardhan,
Seems like you marked my answer correct and unmarked it,

Are you looking for something more!

Please let me know

Thanks and Regards
Rahul

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