cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Audreyma
Helper III
Helper III

Exclude an option in edit page if it has been selected in other records

Hi everyone,

 

I have an option set field in edit page.

 

Now I hope that when entering the edit page, I can only select options which hasn't been select in other records (my current option should be selectable ).

However, with the below code, when opening the edit page, my current option will be deselected and will be hided with other selected options.

Audreyma_1-1630554524959.png

 

Audreyma_2-1630554577660.png

 

Below is the code I'm using, any advice about it?

I use fetchxml to retrieve all options selected in existing records(including the current option ), the final results are saved in "oparr" array.

curoption is the option which I selected in current edit page.  "exop" is the array which I excluded curoption from "oparr" array.

function getexistingop(URL2) {
  var selectLicense = $("#licensekey").val();
  var URL2 = "/fetcharray/?licensekey=" + selectLicense + "";
 {
    $.ajax({
      type: "GET",
      url: URL2,
      dataType: "json",
      async: false
    }).done(function (json) {
        var curoption = parseInt($("#numberselection").val());
        const results = json.results
        const atnum= results.map(result => result.Autoannouncenumber);
        const newarr = atnum.map(arr => arr.slice(-2));
        const oparr = newarr.map(exop=> Number(exop) + 912129999);
        const exop = oparr.filter(val => val !== curoption);
        for(var i=0; i < exop.length; i++){
             $("#numberselection option[value="+exop[i]+"]").hide();
        };
    }).fail(function(jqXHR, textStatus, errorThrown){
        $("#numberselection option").show(); 
    });  
  }
};

$(document).ready(function () {
    $("#licensekey").change(function () { getexistingop(); });
    $("#licensekey").change()
});

 

0 REPLIES 0

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (1,080)