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.
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()
});

Report
All responses (
Answers (