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.

Request State and state should be in Sync

Debasis Pati
Tera Guru

I want my request state field values and state field values to be in sync . Like we have for incident for incident sync we have a business rule oob "Copy State to Incident State".
I have same values as state choices present in request state field as well.
i want to sync them i tried to replicate the same business rule in sc_request table but not able to find the state field in the set value

DebasisPati_0-1765432958505.png

@Ankur Bawiskar any suggestions?

 

 

1 ACCEPTED SOLUTION

Deepak Shaerma
Kilo Sage
Kilo Sage

Hi @Debasis Pati 

Scenario A: If your Backend Values match EXACTLY If you have verified that the backend values for both fields are identical (e.g., both use 1, 2, 3 or both use open, closed),

(function executeRule(current, previous /*null when async*/) {
    // Copy State to Request State
    current.request_state = current.state; 
})(current, previous);

 

Scenario B: If your Backend Values are DIFFERENT (Most Likely) In most ServiceNow instances, State uses numbers (1, 2, 3) and Request State uses strings (new, in_process, closed_complete). You cannot simply copy them; you must map them.

(function executeRule(current, previous /*null when async*/) {

    var stateValue = current.getValue('state');
    
    // Map State (Integer) to Request State (String)
    // Adjust the numbers (1, 2, 3) and strings ('new', etc.) to match your instance choices
    if (stateValue == '1') { // New/Open
        current.setValue('request_state', 'pending'); 
    } else if (stateValue == '2') { // In Progress
        current.setValue('request_state', 'in_process');
    } else if (stateValue == '3') { // Closed Complete
        current.setValue('request_state', 'closed_complete');
    } else if (stateValue == '4') { // Closed Incomplete
        current.setValue('request_state', 'closed_incomplete');
    } else if (stateValue == '7') { // Closed Skipped
        current.setValue('request_state', 'closed_skipped');
    }
    
})(current, previous);

 

Happy to help! If this resolved your issue, kindly mark it as the correct answer   and Helpful and close the thread 🔒 so others can benefit too.

Warm Regards,

Deepak Sharma

Community Rising Star 2025



View solution in original post

3 REPLIES 3

Deepak Shaerma
Kilo Sage
Kilo Sage

Hi @Debasis Pati 

Scenario A: If your Backend Values match EXACTLY If you have verified that the backend values for both fields are identical (e.g., both use 1, 2, 3 or both use open, closed),

(function executeRule(current, previous /*null when async*/) {
    // Copy State to Request State
    current.request_state = current.state; 
})(current, previous);

 

Scenario B: If your Backend Values are DIFFERENT (Most Likely) In most ServiceNow instances, State uses numbers (1, 2, 3) and Request State uses strings (new, in_process, closed_complete). You cannot simply copy them; you must map them.

(function executeRule(current, previous /*null when async*/) {

    var stateValue = current.getValue('state');
    
    // Map State (Integer) to Request State (String)
    // Adjust the numbers (1, 2, 3) and strings ('new', etc.) to match your instance choices
    if (stateValue == '1') { // New/Open
        current.setValue('request_state', 'pending'); 
    } else if (stateValue == '2') { // In Progress
        current.setValue('request_state', 'in_process');
    } else if (stateValue == '3') { // Closed Complete
        current.setValue('request_state', 'closed_complete');
    } else if (stateValue == '4') { // Closed Incomplete
        current.setValue('request_state', 'closed_incomplete');
    } else if (stateValue == '7') { // Closed Skipped
        current.setValue('request_state', 'closed_skipped');
    }
    
})(current, previous);

 

Happy to help! If this resolved your issue, kindly mark it as the correct answer   and Helpful and close the thread 🔒 so others can benefit too.

Warm Regards,

Deepak Sharma

Community Rising Star 2025



Ankur Bawiskar
Tera Patron
Tera Patron

@Debasis Pati 

both Request State and State have different meanings

Request state -> mostly used to track status of request such as Pending Approval, Approved etc

State field -> on REQ it's inherited from Task table

I won't recommend to sync.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

OlaN
Tera Sage
Tera Sage

Hi,

As Deepak explained the underlying data is different on the two fields so no direct mapping can be done.

And if you want to avoid the scripting solution provided, simply create multiple business rules that sets the value of the requested_state depending on the value of the state field. Create one rule for each state transition.

No coding necessary.

Example below.

copy-request-state-1.png

copy-request-state-2.png