Accessing information about secondary entities with GetContextInfo

Less than one minute read time.

Secondary entities are technically never in context so the GetContextInfo method doesn't work for these entities. For example if you wanted to get the current address id this would not work: GetContextInfo('address', 'addr_addressid');

However when you go into the edit screen of a secondary entity, like address, CRM puts the id of that entity into the query string. You can access values in the query string server side with the Values collection. So to get the current addr_addressid you can use Values('addr_addressid').

Note that only the address id is put into the query string. So if you want to access other information about the address you will need to use code like the following:

address = CRM.FindRecord('address', 'addr_addressid=' + Values('addr_addressid'));
city = address.addr_city;

  • Hi Cowper,

    You should be able to use Key16 for this. So replace Values("prod_productid") with Values("Key16").

    Regards,

    Jack

  • This doesn't seem to work for the NewProduct secondary entity. I'm trying to validate the prod_code field to ensure duplicates are not entered. To do this I need to exclude the current record from my query, eg in the prod_code validate script:

    var qry=CRM.CreateQueryObj("SELECT prod_code FROM NewProduct WHERE prod_code='" + Values("prod_code") + "' AND prod_productid<>" + Values("prod_productid") + " AND prod_deleted IS NULL");

    qry.SelectSql();

    if (! qry.EOF){

    ErrorStr="Product code " + Values("prod_code") + " exists already.";

    Valid=false;

    }

    However, Values("prod_productid") always returns undefined.

    (I realise I will have to handle new product records as well as editing existing ones - just trying to validate the edits for now.)

    How can I find the prod_productid when editing (and adding) product records? Or is there a better way of testing for duplicate prod_code entries?

    Thanks!