Can the crm.sdata be used to push a value into another field on the EntryForm?

Hello,

I have modified the SData code slightly from the original example 1 on the api help site and it works except.. when there is a space in the option value eg: "SUMMER BALL", it is ignored. If the value is one word "SUMMERBALL" is works.

I understood that when the choices were added to a selection list, the Code is provided for the purpose of selecting behind the scenes and to use in code such as this.

It doesn't appear to work at all in IE 11 but in Chrome, it does select an option just not the right one into the field if the code has two or more words in the translation. The code is being used in the OpportunityDetailBox - CustomContent.

/*
crm.ready(function()
{
var oContextInf = crm.getArgs();
if ((oContextInf.Act == "1190" || oContextInf.Act == "261" || oContextInf.Act == "142"))
{
var compID = crm.fields("oppo_primarycompanyid").value();
var successCompany = function (crmRecord)
{
crm.infoMessage("The company would like to be invited to the :" + crmRecord.comp_invitetotheball);
crm('oppo_invitetotheball').value(crmRecord.comp_invitetotheball);
}
crm.sdata({
entity: "company",
id: compID,
success: successCompany
});
}
}); */

Thank you for any helping tips you can give.

Regards,

Penny

  • 0

    Hi Penny,

    I've reproduced that behaviour here. I'd put this one down more as ambiguity than anything else.

    When you're checking record.fieldname, it's returning the translated value for the select (the green values in the code below). That field is localised. You can confirm this by using Fiddler to inspect the result of the SData request on the Company entity:

    System Administrator
    2013-07-23T11:15:00+0100
    Summer ball
    System Administrator

    When you try to set the value of a select using value() or val(), it's setting the value for the field, which is in effect the CRM caption code. These are the yellow values in the code. Here's what it's trying to set, as per a basic example:


    ">springball">Springball
    ">summerball">Summer ball
    ">autumnball">Autumn ball
    ">winterball">Winter ball
    --None--

    In this example, "Springball" would work, since the value and translated text are the same. "Summer ball" doesn't work, because they're different.

    Now, I'd assume that when this is working for you, it's because the caption code and translation for that given select value are identical. So: we just need a way of setting the selected index based on the text. This will work:


    crm.ready(function() {

    var oContextInf = crm.getArgs();

    if ((oContextInf.Act == "1190" || oContextInf.Act == "261" || oContextInf.Act == "142")) {

    var compID = crm.fields("oppo_primarycompanyid").value();

    var successCompany = function (crmRecord) {

    crm.infoMessage("The company would like to be invited to the: " + crmRecord.comp_invitetotheball);

    $("#oppo_invitetotheball option").filter(function() {
    return this.text == crmRecord.comp_invitetotheball;
    }).attr('selected', true);
    }
    crm.sdata({
    entity: "company",
    id: compID,
    success: successCompany
    });
    }
    });

    By the way, I reproduced your original issue using IE with no compatibility mode enabled on CRM 7.2g.

    Thanks,
    Rob

  • 0

    Hi Rob,

    Thank you for your help. Working beautifully.

    The field name and "option" for the .filter(function().. I would not have found. I was thinking it would be something like option:selected so you have saved me a lot of time and testing!

    Best regards,

    Penny

  • 0

    No problem at all, you're very welcome!