How to populate Request and Task company fields from the Request Item Company

Sam Ogden
Tera Guru

Hi,

We have multiple catalog Items setup that have the variable of customer - this is a reference field of the core_company table.

I have a business rule in place which sets the answer on this customer variable in the company field on the sc_req_item table with the following code:

Runs Before Insert

current.company = current.variables.customer;

I need the same company name to be filled in on the sc_request and sc_task tables.   Can this be achieved from the same business rule.   I tried the following but with no luck:

sc_task.company = sc_req_item.company;

SC_request.company = sc_req_item.company;

Or will I need a separate business rule?   any help will be greatly appreciated.

Thanks

1 ACCEPTED SOLUTION

HI Joe,



Thanks for the speedy response, just tried your advice and seems to work a treat.   I thought it would be something to do with the order they were submitted to the db.   Still trying to get to grips with the system.



Thanks



Sam


View solution in original post

3 REPLIES 3

Joe McCarty1
ServiceNow Employee
ServiceNow Employee

An oddity of the Catalog is that the Request record is actually committed to the db after the RITMs and your business rule runs before even the RITM is in the database.   So you won't be able to use the same business rule.   Try adding a before business rule to the request.   You're model though assumes the company will be the same across all requested items.   Maybe ok, just wanted to point it out.   It would be something like:



var item = new GlideRecord('sc_req_item');


item.addQuery('request', current.sys_id);


item.query();



if (item.next())


        current.company = item.company;



For catalog tasks, depending on your workflow, they likely don't exist till after the approval stage.   In which case a before insert on the RITM also won't be able to set those, requiring a before insert on the sc_task:



current.company = current.request_item.company;



So likely you will need 3 business rules to accomplish what you would like to do simply because of the timing that the records are available.


HI Joe,



Thanks for the speedy response, just tried your advice and seems to work a treat.   I thought it would be something to do with the order they were submitted to the db.   Still trying to get to grips with the system.



Thanks



Sam


nayanawadhiya1
Kilo Sage

Hey Sam,



On these tables sc_request and sc_task do you have custom field for company??


And that custom field is also referring to "COMPANY" table.



Then create separate BR -


Before BR is for "Request" table updation


After BR is for "Catalog task" table updation.