need to fetch task number from the email body

srinidhi
Tera Guru

Hello All,

 

I need to fetch sctask number from the email body and I need to update the record.

please help me with the script.

example number: SCTASK1234567.

 

Thanks.

1 ACCEPTED SOLUTION

Musab Rasheed
Tera Sage
Tera Sage

Hello,

Below is example of fetching number from Subject, you can replicate for body as well.

https://www.servicenow.com/community/service-management-forum/need-to-extract-incident-number-or-cha...

Please hit like and mark my response as correct if that helps
Regards,
Musab

View solution in original post

13 REPLIES 13

@Musab Rasheed@Ankur Bawiskar 

The above link helped me in fetching the task number.

but am unable to update the reference field from the script.

 

(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
	var subject = email.subject.toString();
        var regex = new SNC.Regex('/SCTASK\\d{7}/im');
        var match = regex.match(subject);
        var task = new GlideRecord('sc_task');

    task.addQuery('number',match);
    task.query();
    while(task.next())
    {
 
        task.work_notes = 'email.body';
		task.u_digilocker.u_locker_status = 2;
        task.update();
    }
 
})(current, event, email, logger, classifier);

 

Which is reference field here ? generally you should pass sys id as reference field value but I don't see it here 

Please hit like and mark my response as correct if that helps
Regards,
Musab

can you provide me the sample syntax please.

like

task.assigned_to = "sys id of user";

Like this

Please hit like and mark my response as correct if that helps
Regards,
Musab

Hello @Ankur Bawiskar  @Musab Rasheed 

 

As per the above requirement i written below script. First part is working fine (gliding to task table and updating the worknotes)

 

But second part is not working (unable to update the stockroom table).

can you please and help me.

 

 var task = new GlideRecord('sc_task');
	task.addQuery('number',match);
    task.query();
    while(task.next())
    {
		var status = task.getValue('u_digilocker');
		gs.info('namee: '+ status);
        task.work_notes = email.body_text();
		task.state = 2;
        task.update();
	
		var st = new GlideRecord('alm_stockroom');
		st.addQuery('name',status);
	gs.info('abcd' + status);
		st.query();
	while(st.next()){
		st.u_locker_status = 2;
		st.update();