How to create cross-scoped columns with Fluent
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I'm having some issues defining the correct schema for creating columns cross-scope using Fluent syntax (the column is in my scoped app, but exists on an OOB or other table).
I distinctly remember getting this to work using the forced typecast prescribed in the docs. The documentation states:
"Note: To add columns to an existing table in a different application scope, you can provide the name of the table without the application scope followed by as any. The column names must begin with the application scope instead."
However, this seems to have stopped working (at least for me) with the new 4.0.0 update.
What exactly is the correct approach for defining a column in a differently scoped table? Examples would be appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @AdrianJ26763850,
For defining a column in a different scoped table using Fluent syntax, especially with the newer updates, the approach has shifted from a simple typecast to ensuring proper cross-scope permissions are in place first.
Follow the given approach please:
Before your script will work, you need to explicitly grant your application permission to modify the target table.
Navigate to System Applications > Application Cross-Scope Access.
Create a new record.
Source Scope: Your current application scope.
Target Scope: The scope of the table you want to modify (e.g., Global).
Operation: Set to create, read, and write.
Target Name: The name of the table you are adding a column to.
Status: Set to "Allowed".
Note: Do the above for all create, read, and write access.
Next, ensure the target table itself allows access from other scopes.
Navigate to System Definition > Tables.
Open the record for the table you want to modify.
In the Application Access tab, check the box for Can create, Can update, and Can delete. You may also need to check Allow access to this table via web services.
Once the permissions are correctly configured, you can use the following syntax in your script:
(function(context) {
'use strict';
var schema = {
name: 'incident'
};
// Add your cross-scope column
schema.columns = [
{
name: 'x_my_app_my_custom_field',
type: 'string',
maxLength: 100
}
];
return schema;
})(context);
Note: You still need to prefix the column name with your application's scope. Let's say your application scope is x_my_app and you want to add a column to the incident table.
Hope this helps!
Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Yes, this looks like a bug in 4.0.0 and we are going to get a fix for this in 4.0.1 which should be available this week. Thanks for reporting it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
@AdrianJ26763850 This was fixed in 4.0.1 if you upgrade, can cast the table name `as any` to surpress the error.
https://github.com/ServiceNow/sdk-examples/blob/main/table-sample/src/fluent/table-custom-column.now...