- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2018 03:50 PM
Hi,
I am in the process of creating an app. Basically our goal is to have to as a scoped app. When we need to extend this to other areas in the company, we will just simply create another scoped app and extends all the tables from the master scoped app. So we will have one master scoped app, then will have multiple scoped apps which are basically the same as the master scoped app.
This way, we can maintain our code in the master scoped app but also give flexibility to the cild scoped app in case there are some specific customization for just that area. In each child scoped app, there is a record in a custom table to store all kinds of configuration. Here is my question:
Since all the scripting is stored in the master scoped app, how can all the scripts be dynamic enough to pick up the configuration record in the custom table in each child scoped app?
For example. I have a onChange client script on a form. When the value of this field changes, an onChange function is trigger. In this function, I will need to check a value in the configuration record in order to continue. So he is what the onChange function potentially looks like:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var gr = new GlideRecord("[tablename]");
gr.query();
if(gr.next()){
//get value of the property that I need
}
}
**I understand that it is not recommended to use GlideRecord in client script, but it is easier to explain my situation**
Now since this script is in the master scoped app, I wouldn't know the namespace of the app using this script. Is there a way I can get the namespace of the current app from the client script?
the table name for the configuration table will be like x_company_app1_config, x_company_app2_config.
g_form.getTableName() is the closest I can get. It gives me the current table name, like x_company_app1_table1 which I can just trip the namespace(x_company_app1) out of it but I prefer not to do it because it could be inaccurate depends on how we name our child scope app and such.
OR is there a better way to achieve what I want? To have one master app and "spawn" it to different areas to use it. But we only have to maintain the master scoped app for the most part.
Please advise
Sam
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2018 04:04 AM
Hi Samuel,
I am not sure about the Best practice(since it will require full requirement analysis), but if you want to get the current child scope app namespace you can use the display Business rule and store the child scope app namespace in g_scratchpad object and then use that value from g_scratchpad object in your Client script:
Display BR:
g_scratchpad.childAppScopeName = gs.getCurrentScopeName();
Client Script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var currentAppScopeName = g_scratchpad.childAppScopeName;
// use currentAppScopeName to pass your app scope name
}
Please let me know if this works for you OR if I have misunderstood something here. You can also check for gs.getCallerScopeName() if it is useful for you
Please mark it correct/helpful, if it resolves your problem.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2018 04:04 AM
Hi Samuel,
I am not sure about the Best practice(since it will require full requirement analysis), but if you want to get the current child scope app namespace you can use the display Business rule and store the child scope app namespace in g_scratchpad object and then use that value from g_scratchpad object in your Client script:
Display BR:
g_scratchpad.childAppScopeName = gs.getCurrentScopeName();
Client Script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var currentAppScopeName = g_scratchpad.childAppScopeName;
// use currentAppScopeName to pass your app scope name
}
Please let me know if this works for you OR if I have misunderstood something here. You can also check for gs.getCallerScopeName() if it is useful for you
Please mark it correct/helpful, if it resolves your problem.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2018 07:08 AM
Brilliant! Thanks.
I ended up creating this business rule in the child scoped app and it worked. I was hoping to create that business rule in the master scoped app so I don't have to replicate it every time I create a child scoped app. I thought gs.getCallerScopeName() would return what I need but it doesn't. I created the BR in the master scoped app and gs.getCallerScopeName() returns the name of the master scoped app when i trigger it from the child scoped app table. That doesn't seem right to me.
Anyway, creating a BR in the child scoped app with gs.getCurrentScopeName() works. I will just have to documented this step when we create a new child scoped app.
Thanks!
Sam