CRM Create Script - change the default value based on an IF statement

SOLVED

I've been scratching my head on this one for the past couple of days and wonder if anyone can help? I've seen a couple of similar queries here but when I've tried to implement the results I've not had any luck. 

I'm trying to set the default value of a fee field to 150 when the loan type and loan purpose meet specific criteria, so far I've had no luck! 

Below is what I've tried using most recently. 

var Application = CRM.FindRecord('application',Value('appl_applicationid'));
var loanType = CRM.GetContextInfo("Application","appl_loantype");
if (Application.appl_loan_purpose == 'Purchase' && loanType == 'Buy')
{
	DefaultValue = 150;
}
else
{
	DefaultValue = 100;
}

Thanks! 

James.

Parents
  • 0

    If I recall correctly, you cannot use GetContextInfo with a custom entity.  If you switch this out to an SQL query, it should work.

    Hope this helps!!

  • 0 in reply to Michele Gaw

    You can as I have used it in the past, for example I use the following on CreateScript to control the searching on an Adv. Search Select

    ​var myrecord = CRM.GetContextInfo("Project_Milestone","prmi_opportunityid");
    SearchSQL = "rebr_opportunityid=" + myrecord;

    I'm weak on JavaScript but James's script doesn't 100% make sense to me - the var gets the ID from appl_applicationid but doesn't do anything with it, then in the IF I'm not shaw how it is gettting the appl_loan_purpose field, is this not confusing. shouldn't it be something like 

    var Purpose = CRM.GetContecxtInfo("Application","appl_load_purpose");
    var loanType = CRM.GetContextInfo("Application","appl_loantype");
    if (Purpose == 'Purchase' && loanType == 'Buy')
    ......
Reply
  • 0 in reply to Michele Gaw

    You can as I have used it in the past, for example I use the following on CreateScript to control the searching on an Adv. Search Select

    ​var myrecord = CRM.GetContextInfo("Project_Milestone","prmi_opportunityid");
    SearchSQL = "rebr_opportunityid=" + myrecord;

    I'm weak on JavaScript but James's script doesn't 100% make sense to me - the var gets the ID from appl_applicationid but doesn't do anything with it, then in the IF I'm not shaw how it is gettting the appl_loan_purpose field, is this not confusing. shouldn't it be something like 

    var Purpose = CRM.GetContecxtInfo("Application","appl_load_purpose");
    var loanType = CRM.GetContextInfo("Application","appl_loantype");
    if (Purpose == 'Purchase' && loanType == 'Buy')
    ......
Children