How To: Button used global variable or function

@DryChips,

In this case, when calling the function, the value must be replaced with the field value like so:

val(fd.field('FieldName').value);

Or replace value in the PnP function and call the val function without the parameter:

window.val = function validateCC(){
   pnp.sp.web.lists.getByTitle("POWERBiV2").items.filter("User_Principle_Name eq '" +  fd.field('FieldName').value + "'").get().then(function(items){
        if (items.length > 0){
        alert("This user already exists, please edit this record below.");
           $($(fd.field('User_Principle_Name').$el).find('input')[0]).attr('style', 'border-color: #6CEE5A;');
        }
   })
}

YESSSSSS!!!! You are a SUPER STAR!

Many many thanks!!!! :smiley:

For future users:

Place this code in the button property: val(fd.field('FieldName').value);

Then add the code below, outside of fd.spRendered(function){}

window.val = function validateCC(){
   pnp.sp.web.lists.getByTitle("POWERBiV2").items.filter("User_Principle_Name eq '" +  fd.field('FieldName').value + "'").get().then(function(items){
        if (items.length > 0){
        alert("This user already exists, please edit this record below.");
           $($(fd.field('User_Principle_Name').$el).find('input')[0]).attr('style', 'border-color: #6CEE5A;');
        }
   })
}
1 Like