Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Can anyone share rest api code for adding Affected Ci's to the Existing change Request ?

Darshan A
Kilo Contributor

I'm able to create a Change ticket using rest api,, after that I want to add more Ci's to affected Ci's part using Rest Api,, I have gone through many posts,, they have suggested to use task_ci but im not able to figure out how to accomplish my work using that table, it would be easy if someone shares rest api code for that , thanks in advance.

1 ACCEPTED SOLUTION

Alikutty A
Tera Sage

Hi,

You can go to Rest API explorer in Service Now and get your required code for triggering the request. Follow these steps:

1) Go to rest api explorer and select these details as shown (Table is task_ci)

find_real_file.png

 

2) Provide change request and CI sys_id as input to your request

find_real_file.png

 

3) You could also provide a CI name if you are sending it via a script by dot walking on the ci_item.name field. To get the script, scroll down further and select the required language of your choice.

find_real_file.png

 

Your Rest endpoint would be: 

POST https://instance_name.service-now.com/api/now/table/task_ci
 

Headers

Accept:  application/json
Content-Type:  application/json

Request Body
{"ci_item":"572928028727227928298228222","task":"784874808727227928298228222"}

Here ci_item is your CI sys_id and task is your change request sys_id received while creating the change. If you send
ci_item.name, then you can also pass the CI as Name

 

 

 

View solution in original post

3 REPLIES 3

Deepak Ingale1
Mega Sage

Hi Darshan,

 

Are you using OOB Table REST API to create a change? If that is the case, you can write an AFTER INSERT business rule on change_request table to create records in task_ci table

 

Note: Please mark reply as correct if it has answered your question or mark it as helpful if you find it helpful

 

var tc = new GlideRecord("task_ci");
tc.initialize();
tc.task = current.getValue("sys_id");
tc.ci_item = "Put SYS ID OF CI HERE";
tc.insert();


Alikutty A
Tera Sage

Hi,

You can go to Rest API explorer in Service Now and get your required code for triggering the request. Follow these steps:

1) Go to rest api explorer and select these details as shown (Table is task_ci)

find_real_file.png

 

2) Provide change request and CI sys_id as input to your request

find_real_file.png

 

3) You could also provide a CI name if you are sending it via a script by dot walking on the ci_item.name field. To get the script, scroll down further and select the required language of your choice.

find_real_file.png

 

Your Rest endpoint would be: 

POST https://instance_name.service-now.com/api/now/table/task_ci
 

Headers

Accept:  application/json
Content-Type:  application/json

Request Body
{"ci_item":"572928028727227928298228222","task":"784874808727227928298228222"}

Here ci_item is your CI sys_id and task is your change request sys_id received while creating the change. If you send
ci_item.name, then you can also pass the CI as Name

 

 

 

Praful5
Kilo Explorer

Hi,

 

I am able to attach CI through API (api/now/table/task_ci). Actually I am passing the server name (not sys_id) as ci_item. And change number as task in the body. It works fine.

But, I have same server name in multiple classes. I want to put a filter and search the server name from different class. We can How, can I put the filter and fetch CIs from different class through API

find_real_file.png

I am able to do this from Web UI. But I have to do this through API.

Kindly help me to put this filter when I do POST

 

Thanks

-Praful