I have a variable counter (question) that I tried to make global. I have button (Button0) that I want to increment the counter and then call a function. I get a message that the “question” variable is not defined. I defined the counter and function both inside and outside of fd.spRendered but neither worked.
How can I have a button use a variable or call a function?
Hi @AlexZver
I am trying to implement a similar scenario. I want the button to execute a function in Javascript but the console states that the function was not defined.
Could you please guide me how I need to define the function so it is accessable to the button?
Below is my shortened code.
I need the variable to remain the same after the form is cleared (I want to preserve the email for the next entry on the form). Is this the right method to do this? I can't get it to work.
//Function will send Pnp request to search for value in list and let user know if name exists in list
window.val = function validateCC(value){
pnp.sp.web.lists.getByTitle("POWERBiV2").items.filter("User_Principle_Name eq '" + value + "'").get().then(function(items){
if (fd.field('User_Principle_Name').value.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;');
fd.field('SUPN').value = fd.field('User_Principle_Name').value;
$('.EditAccess').show();
}
});
}
The function isn't doing anything. No errors in console on load, though it comes with length is not defined.
Also, I don't understand your condition: if (fd.field('User_Principle_Name').value.items.length > 0)
Shouldn't you check if any items were returned on PnP request like so: if(items.length > 0)
I want to call the function in a button. So I have added: validateCC(); in the button property but nothing happens.
Yep, the condition if (fd.field('User_Principle_Name').value.items.length > 0) was added in the JS editor to test and see if it works! But turns out it doesn't.
I added the code below outside of fd.spRendered(function(){ and added val() in the button click property and nothing happens. No errors appear in console either.
Where am I going wrong?
//Function will send Pnp request to search for value in list and let user know if name exists in list
window.val = function validateCC(value){
pnp.sp.web.lists.getByTitle("POWERBiV2").items.filter("User_Principle_Name eq '" + 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;');
fd.field('SUPN').value = fd.field('User_Principle_Name').value;
$('.EditAccess').show();
}
});
}
I mean that when you call the function without the value parameter like so: val(); the filter in PnP function looks is invalid and the function doesn't return any value:
pnp.sp.web.lists.getByTitle("POWERBiV2").items.filter("User_Principle_Name eq 'undefined'").get()
You must call this function with parameter like so: val('Jane Doe')
The user principle name is manually typed into a field and then saved to a SharePoint list. I am doing a lookup to the same SharePoint list to check if the user principle name is present. If it present, I will alert the user so that they don't create the same user principle name but rather a different one.
I have already enabled "enforce unique" values to my list but I want to create a separate function to do another task for me.