CRM.FindRecord Context in Create Script

I'm still trying to 'connect the dots' in my understanding of the javascript Create and Validate rule scripts. Specifically, can 'out of context' data be queried? Or maybe there is another way to accomplish my task?

In a case workflow, I need to filter the 'Assigned To User' SSA to display only users in team 'Regulatory'. My approach is to, 1) Get the chan_channelid of the channel where the chan_description = Regulatory. 2) Iterate the channel_link table to get the user Id's linked to the channelId. 3) Use RemoveLookUp() to remove the users from the selection list who are not on the team.

Starting with the first step to query the channel table, I get 'Channel Id is undefined' result from my simple debug Create script:

var channel = CRM.FindRecord("channel","chan_description='Regulatory'");
valid = false;
ErrorStr = "Channel Id is " + channel.chan_channelid;

I've tried different filters (second param in FindRecord), with and without quotations.

What am I missing?

  • 0

    CRM.FindRecord is server side, not client side so you cannot use it in a create script. If you are using 7.2 or later, you can use crm.sdata to get server side data client side.

  • 0

    Thanks for the reply, Toby.

    CRM v7.3. I'm looking at some of the training material and the way I'm reading it is that Create and Validate run server side, but the limitation is the 'context'.

    From the 'CRM 7.2 Advanced Features Course Reference Guide.pdf',

    Server Side JavaScript (Create, Validate)
    ...Within server-side scripts you can refer to the complete CRM object model, so you refer directly to entries within the current context.

    I'll take a look at the sdata information. The bigger picture is a standard way (method?) to query the database irrespective of the event or context.

    -Paul

  • 0

    I think that the channel record object properties may be case sensitive. Try channel.Chan_ChannelId.

    Alternatively, try channel("chan_channelid") - the field name isn't case sensitive when passed as a string.

    To get the record ID, you could also use channel.RecordID.

  • 0

    Can you not just set the SearchSQL= against the field in the create script

    SearchSQL="user_primarychannelid=1";