Select List Option and Trigger Input of Value

Hello,

I am hoping to have an option in a normal select field selected and the value chained in the statement, entered directly to a integer field.

I am not able to trigger the update on selection until the screen is submitted - saved and then changed again. It then fires the update of the selection.

The value is used in a small formula script which requires updating on entry as well. This is also working once the screen has been re-opened.

I have seen this behaviour with the case_assigneduseridInput trigger that changes the user name when a product area is selected and this is what I am attempting to see function.

Is there a way to do this - in jquery (great!) or javascript with CRM?

Here is my attempt - in the custom content of the oppo progress screen:

crm.ready(function(){
var oEcontextInfo = crm.getArgs()
if (oEcontextInfo.Act == "1190" || oEcontextInfo.Act == "263")
{
if (crm("oppo_stage").value()== "Demo")
{
document.forms[0].oppo_certainty.onchange();
crm('oppo_certainty').value(10);
}
else if (crm("oppo_stage").value()== "Quoted")
{
document.forms[0].oppo_certainty.onchange();
crm('oppo_certainty').value(25);
}
}})

Thank you.. in anticipation :)

Best Regards,

Penny Vaskess



  • 0

    Rob,

    This is exactly what I want to happen!

    I did go back to the drawing board and reinvent / copy code from Jeff's training that behaved a little better.

    The stage - once selected, triggered the input of the value that is chained to the stage - with Insert/Edit. The stage however, is showing as blank so the code I copied needs more work.

    This is jquery - and so much simpler!

    Thank you Rob. :)

    Rob - can you tell me what my problem was with the below code that I had? I have stored these js files in the custom folder for js files with the names OppoEdit.js and zzzOppoEdit.js. The onchange ( this.value = OppoEdit.opCertain(this.value); ) is called from the oppo stage field onchange script in the oppo progress screen.

    OppoEdit.js

    var OppoEdit = OppoEdit || {};

    OppoEdit.opFeasibility = function (x) {

    var opSt = crm("oppo_stage").value();

    switch (opSt) {

    case 'Demo':

    crm("oppo_certainty").value(5);

    break;

    case 'Quoted':

    crm("oppo_certainty").value(25);

    break;

    case 'Negotiating':

    crm("oppo_certainty").value(50);

    break;

    case 'ReQuoted':

    crm("oppo_certainty").value(75);

    break;

    default:

    crm("oppo_certainty").value(0);

    }

    }

    zzzOppoEdit.js

    crm.ready(function () {

    var contextInfo = crm.getArgs();

    crm.infoMessage(contextInfo.Act);

    if (contextInfo.Act == "1190" || contextInfo.Act == "263") {

    var foP_forecast = crm.fields("oppo_forecast");

    if (foP_forecast.getMode() == "edit")

    $("#oppo_certainty").change(function () { this.value = OppoEdit.opCertain(this.value) });

    })

    I believe the problem is my misunderstanding of writing a function. Using function (x) has confused me as it is not referring to anything and this may be my issue. Any pointers or guidance here would be really helpful.

    Thanks again Rob.

    Best Regards,

    Penny Vaskess

  • 0

    oops.. OppoEdit.opFeasibility should be OppoEdit.opCertain. This is what I have in the code. Sorry about that!

  • 0

    Hi Penny,

    It looks like this script is only firing when the page has completed loading. Am I wrong in saying that you want it to fire when an option is selected? In that case you'll need to attach (not replace) an onchange event to the element.

    I'm not entirely clear on what's being sought here, but let's say that you wanted to change oppo_certainty based on a value selected in oppo_stage, and that you wanted this to happen on the NewOpportunityDirect and EditOpportunity screens. Here's how this could be done:

    crm.ready(function () {

    var oEcontextInfo = crm.getArgs();

    if (oEcontextInfo.Act == "1190" || oEcontextInfo.Act == "263") {

    // Attach an onchange to oppo_stage

    $('#oppo_stage').change(function () {

    if (crm("oppo_stage").value() == "Demo") {

    // Uncomment if you want an onchange event on oppo_certainty to fire

    // $('#oppo_certainty').change();

    crm('oppo_certainty').value('10');

    }

    else if (crm("oppo_stage").value()== "Quoted")

    {

    // Uncomment if you want an onchange event on oppo_certainty to fire

    // $('#oppo_certainty').change();

    crm('oppo_certainty').value('25');

    }

    });

    }

    });

    You could of course put most of this into an OnChange function on your target field. I could be way off the mark on this, just let me know if there's anything else I can help with.

    Thanks,

    Rob

  • 0

    Hiya,

    It looks like there's a small syntax error in zzzOppoEdit.js. Aside from that, you're attaching the OnChange event to oppo_certainty - you want to attach it to the element that's being changed (in this case, probably oppo_stage). You don't need to attach an event to oppo_certainty, unless you wanted to change something as the result of a user keying a value into that field.

    Here's the amended code:

    // OppoEdit.js

    var OppoEdit = OppoEdit || {};

    OppoEdit.opCertain = function () {

    console.log("function firing");

    var opSt = crm("oppo_stage").value();

    switch (opSt) {

    case 'Demo':

    crm("oppo_certainty").value(5);

    break;

    case 'Quoted':

    crm("oppo_certainty").value(25);

    break;

    case 'Negotiating':

    crm("oppo_certainty").value(50);

    break;

    case 'ReQuoted':

    crm("oppo_certainty").value(75);

    break;

    default:

    crm("oppo_certainty").value(0);

    }

    }

    // zzzOppoEdit.js

    crm.ready(function () {

    var contextInfo = crm.getArgs();

    crm.infoMessage(contextInfo.Act);

    if (contextInfo.Act == "1190" || contextInfo.Act == "263") {

    var foP_forecast = crm.fields("oppo_forecast");

    if (foP_forecast.getMode() == "edit")

    $("#oppo_stage").change(function () { OppoEdit.opCertain() });

    }

    });

    I don't think you need to pass anything to the function, or assign the result to anything (there's no return statement anyway), since you're picking up and setting the values directly from the fields. I'm not sure what oppo_forecast is meant to be doing in the above, aside from us making sure that it's editable - I'm sure you could still attach the function there, just keep in mind it'll fire when the forecast value is changed, rather than the stage.

    Thanks,

    Rob

  • 0

    Thank you again Rob.

    I am still having a few difficulties but I will hopefully sort out where the issue is when I use the code within the js files - I must have misunderstood something as I keep getting the message " crm is undefined " and it points to the crm.ready(function.. call.

    Tomorrow is another day and I am sure it will reveal where the issue is!

    Best regards,

    Penny Vaskess

    Sage CRM Certified Consultant

    Perth, Western Australia