Update field in scoped application table

abhisekpramanik
Tera Contributor

Hi Guys,

I am facing some problem to update the field in a table ( corr_coe)which is in a scoped application (x_stap2_coe) from a table in global application (problem ) . I written below code but unable to update and showing undefined .

var prb= current.number;

var rootCause=current.u_root_cause_description;

var gr = new GlideRecord('x_stap2_coe_corr_coe'); // Table name in scoped application

gr.addQuery('problem_number',prb);

gs.addInfoMessage(gr.problem_number); //Undefined

var number=gr.number;

gs.addInfoMessage(number); //Undefined

gr.query();

while (gr.next()) {

//gr.x_stap2_coe_corr_coe.root_cause_details= "Problem number = +prb+\n\n "+rootCause;

gr.root_cause_details= "Problem number = +prb+\n\n "+rootCause;   // No update showing .

gr.update();

}

Please help me .

Thanks,

Abhisek

2 REPLIES 2

bernyalvarado
Mega Sage

Hi Abhisek,



Keep in mind that the intent of scoped application is that one application does not have any influence / effect on other's application's scope. That includes global.



I believe the following article (Understanding Application Scope on the Now Platform (Whitepaper) ) is going to be helpful for you. Specially the following section:


What are some challenges and mitigations I should consider when working with scoped apps?



When you need an artifact such as a business rule or UI policy from a global scope, you have to replicate that in your scoped app to make it part of a script include (Figure 4).   In order to access a function or an artifact referenced in the wrapper script, it should be referenced as appscope.scriptinclude.function. If the wrapper script is defined in a scoped app, then the function or artifact will be available only to that scope and not outside of it. This poses a couple of challenges. One, there may not be any documentation regarding encapsulation of wrapper script unless you explicitly document it.   Second, when making changes to these global artifacts, you need to consider any scoped apps that are impacted. Without proper documentation, you might miss these during your analysis.




scoped-apps-fig-4.png


Figure 4


What are some best practices for scoped apps?



  1. Always create new applications as a scoped app.
  2. When extending a global app, if there are going to be frequent changes to the application or if there are many modifications to the global artifacts, extend the application in global scope.  
  3. If you need to use a global scope artifact in a scoped app, you need to copy the artifact in the scoped app or wrap it with a script include.
  4. Always document the changes you make to the scripts or artifacts of your applications for easier analysis during the upgrade process.
  5. If you are planning to use an API in a scoped app, check out the link given at the end of this article to see what API's are available.
  6. When moving scoped apps from one instance to another, use the publish function to deploy rather than using update sets.
  7. Do not try to move applications from a global scope to a scoped app and vice versa, since there is no direct migration or tools. You have to manually create the new artifacts.


source: Understanding Application Scope on the Now Platform (Whitepaper)



Thanks,


Berny


Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Abhisek,



Create AFTER business rule and make sure target table has create/update operation enabled. Please refer section "Table access setting" in the below blog.


Securing an application using Cross Scope Access, Application Access Settings & Restrict Table Choic...



var prb= current.number;


var rootCause=current.u_root_cause_description;


var gr = new GlideRecord('x_stap2_coe_corr_coe'); // Table name in scoped application


gr.addQuery('problem_number',prb);


gr.query();


while (gr.next()) {


//gr.x_stap2_coe_corr_coe.root_cause_details= "Problem number = +prb+\n\n "+rootCause;


gr.root_cause_details= "This is a test;


gr.update();


}