Important Update: Community URLs redirect issues are partially resolved. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Custom object to compare two different Value lists and throw alert message

sanjithReddy1
Contributor

Hi ,

I am trying to run the below code to compare to GVL in a Questionaire but unfortunately it is not working .Can anybody help me out here Ilya Khen

 

<script type="text/javascript">

     var primary = 81709;

     var secondary = 154;

Sys.Application.add_load(function() {         
          $('#master_btnSave').clone().attr('id', 'master_customBtnSave').insertBefore('#master_btnSave');
          $('#master_btnSave').hide();
          $('#master_customBtnSave').unbind('click').prop("onclick", null).click(function(){ validation('save');return false;});
         
           $('#master_btnApply').clone().attr('id', 'master_customBtnApply').insertBefore('#master_btnApply');
           $('#master_btnApply').hide();
           $('#master_customBtnApply').unbind('click').prop("onclick", null).click(function(){ validation('apply');return false;});
     });

function validation(action){

if($('div[id*="f'+primary+ 'c"]').text().trim() == $('div[id*="f'+secondary+ 'c"]').text().trim())

{

var msg = '[Scores need to be cleared before you save this value]'; 
var title = 'Required Field'; 
Alert(msg,title);

return;

}

 

if(action=='save'){

$('#master_btnSave').click();

}

else if(action=='apply'){

$('#master_btnApply').click();

}

}

</script>

7 REPLIES 7

Ilya_Khen
Champion III

sanjith Reddy,

 

If you use the same GVL for both VL fields, then:

<script type="text/javascript">
var primary = 81709;

var secondary = 154;

Sys.Application.add_load(function() {
$('#master_btnSave').clone().attr('id', 'master_customBtnSave').insertBefore('#master_btnSave');
$('#master_btnSave').hide();
$('#master_customBtnSave').unbind('click').prop("onclick", null).click(function() {
validation('save');
return false;
});

$('#master_btnApply').clone().attr('id', 'master_customBtnApply').insertBefore('#master_btnApply');
$('#master_btnApply').hide();
$('#master_customBtnApply').unbind('click').prop("onclick", null).click(function() {
validation('apply');
return false;
});
});

function validation(action)
{
var primaryValue = $CM.getFieldValue(primary);
var secondaryValue = $CM.getFieldValue(secondary);

primaryValue = primaryValue == null ? "" : primaryValue.toString();
secondaryValue = secondaryValue == null ? "" : secondaryValue.toString();

if (primaryValue == secondaryValue) {
var msg = '[Scores need to be cleared before you save this value]';
var title = 'Required Field';
alert(msg, title);

return;
}

if (action == 'save') {
$('#master_btnSave').click();
} else if (action == 'apply') {
$('#master_btnApply').click();
}
}
</script>

Hi IIya, Thanks for your immediate response

It is Two different Value lists which contains two different GVL.. One value list contains -- yes or no and the other value list contains status. It would also be helpful if I can get a code for comparing Calculated field to one GVL where calc field populates numeric value . Thanks again for your help :-)

I am not sure, how you going to compare Status to Yes/No, as it always gonna be different.

ok we can ignore the Yes/no requirement then .. The other requirement  is Comparing Cal Field i.e if it contains value(numeric) and the status(value list) contains "review not required". Then we need to get a Popup message saying Review not required cannot be selected as Numeric value is populated in the calculated field. Thank you

Calc Field is a Text Field I assume. Then it can be taken only over JQuery element pointer for example.

E.g. David Petty explained TextField - Read failing in custom objects using getFieldValue() function. 

Apologies  for bothering you with  too many questions. The calc field is a numeric field

Yes, essentially same. Over JS or JQuery.