Getting sys_ids of records created from Fluent APIs

Chris Yang
Tera Sage

Hello,

 

I configured an Application Menu via the "ApplicationMenu" fluent API, however, I want to use that object in a "Record" API to create an application module, since there are no dedicate APIs for it. Example code below, see data.application property which expects a sys_id.

 

I read in the docs that Now.ID['id_1'] will resolve in a unique ID, but that's not working. Also tried exporting the output to a variable but no luck. Looking for a solution that I can dynamically resolve the sys_id so that I don't have to build the app first and then retroactively update it.

//menus.now.ts
import { ApplicationMenu, Record } from '@servicenow/sdk/core'

export const appMenu = ApplicationMenu({
    $id: Now.ID['fluent_demo_app_menu'],
    title: 'Fluent Demo App Menu',
    hint: 'hints go here',
    description: 'Descriptions goes here',
    category: '73f1136a3ebc4cfd9f45094e0d01a024',
    roles: ['admin' as any],
    active: true,
    order: 100,
})

Record({
    table: 'sys_app_module',
    $id: Now.ID['my_record_module'],
    data: {
        title: 'My Records',
        application: '2062cef0cdd7483bbb8de89dd723163a',
        // application: appMenu, // not working
        // application: Now.ID['fluent_demo_app_menu'], // not working
        order: 100,
        hint: 'module hint',
        roles: 'admin',
        active: true,
        link_type: 'LIST',
        name: 'x_820676_fludemo_todo_remastered',
        override_menu_roles: false,
        require_confirmation: false,
        uncancelable: false,
    },
})

 

 

 

1 ACCEPTED SOLUTION

Venkat79
ServiceNow Employee
ServiceNow Employee

Hi @Chris Yang,

Thanks for bringing this up.

We are aware of this issue and currently we do not have any alternate solution to it other than what you are doing already.

Our goal is to be able to reference the variables, similar to what you are doing.

 

Record({
    table: 'sys_app_module',
    $id: Now.ID['my_record_module'],
    data: {
        title: 'My Records',
        application: appMenu, // re-use the vairable created earlier
        order: 100,
        hint: 'module hint',
        roles: 'admin',
        active: true,
        link_type: 'LIST',
        name: 'x_820676_fludemo_todo_remastered',
        override_menu_roles: false,
        require_confirmation: false,
        uncancelable: false,
    },
})

 


We are working on improving the experience in future versions of the SDK

Thanks!

View solution in original post

6 REPLIES 6

Hi @Chris Yang ,

 

That's an important detail I've missed. Thanks for clarification!

ryanpalmer
ServiceNow Employee
ServiceNow Employee

Hey @Chris Yang,

 

Wanted to provide an update for you on this. In the 2.0.2 release you will be able to establish references between Record entities and other higher-order entities using their $id property like so:

 

export const appMenu = ApplicationMenu({
    $id: Now.ID['fluent_demo_app_menu'],
    title: 'Fluent Demo App Menu',
})

Record({
    table: 'sys_app_module',
    $id: Now.ID['my_record_module'],
    data: {
        application: appMenu.$id
    },
})

 

 

We'll be releasing 2.0.2 soon so keep an eye out for it. Hopefully this resolves your issue!

Thanks!
- RP