Yash Agrawal1
Tera Guru

Hello ServiceNow Users,

Let's say you want the Initial values of all the fields in the record of a particular table. Many time hear from many users, that it is not possible.

But actually, it is possible.ServiceNow provides you a facility to check the initial values of any record even after that record values updated multiple times.

You Can follow the below code to get the Initial Values of any record in any table.

Here I am fetching all the incidents whose CI's initial value is blank when initially the incident was created.

var arr=[];
var grincident=new GlideRecord('incident');
grincident.query();
while(grincident.next())
 {
	var grhistory=new GlideRecord('sys_history_set');
        grhistory.addQuery('id',grincident.sys_id);
	grhistory.query();
	if(grhistory.next())
	{
	   var name = gs.getXMLText(grhistory.initial_values,"//cmdb_ci");
	   if(name==null)
	   {
                gs.addInfroMessege('Incident has No CI initially-'+grincident.number);
           }
           else
          {
                gs.addInfroMessege('Incident has CI initially-'+grincident.number);
          }
	}

  }
		

Regards,

Yash Agrawal

Comments
Pranav Bhagat
Kilo Sage

Hi Yash

Thank you for sharing it ,I would recommend using Insert/edit sample option for any kind of scripts in your article.

 

@Ashley Snyder shared a article about it do check it out.

Link to article

https://community.servicenow.com/community?id=community_article&sys_id=683e067edbae1c50fb115583ca9619c1

Thanks 

Pranav 

Yash Agrawal1
Tera Guru

Hello Pranav,

Thankyou for your suggestion,I will surely do that.

But just a question,do you know that after getting comment on my article,if now I modified it,your helpful marked will get lost or not.

Regards,

Yash Agrawal

Pranav Bhagat
Kilo Sage

Hi Yash

 

Don't worry ,nothing will be lost 🙂

Yash Agrawal1
Tera Guru

Hello Pranav,

Is it looking Good now.

Regards

Yash Agrawal

Pranav Bhagat
Kilo Sage

yups 🙂

Version history
Last update:
‎09-19-2020 12:14 AM
Updated by: