Javascript is not working when using runJavascript action
Application Type
Traditional Web

The below code i am trying to run into the Runjavascript action.but same code is working in Google crome Console.but in Runjavascript its throwing error because of split function.i am not able to recollect the syntax of that.can any one please check and tell me the issue

"$('#LisbonTheme_wt113_block_wtMainContent_wtGetAllSAE').find('option').each(function() 
{
    var DropdownValue=$(this).val();
    var array = $('#LisbonTheme_wt113_block_wtMainContent_wtInputDisabledValue').val().split(',');
        $.each(array,function(i)
       {
        if (DropdownValue==array[i])
                   {
                     $('#LisbonTheme_wt113_block_wtMainContent_wtGetAllSAE option[value=' + DropdownValue+']').attr('disabled','disabled');
                   }
           }
    );    
});
"

Hi Arkyadeep,

I think as per error the description split is not working. It may be due to some datatype conversion. Please share the appropriate error which your facing in the application. In meantime try looking at the below reference, may be it can help.

https://stackoverflow.com/questions/52547876/javascript-uncaught-typeerror-split-is-not-a-function/52547929

https://stackoverflow.com/questions/51670952/typeerror-val-split-is-not-a-function

Regards,

Saravanan

Same javascript is working in explorer console application and it is showing undefined method.but same method is working in console.whennwe are runjavascriptaction then all " should be replaced with ' but in split function in javascript it should be split(",").Here is the problem I think because of " because in runjavascript action all " should be replaced with '.how to achive that thing any idea?

mvp_badge
MVP

Hi Arkyadeep,

I have tried to implement the same use-case using the mentioned jQuery and it's working fine for me.

Check this Sample screen DisableDropdownOpt_JS

Used JQuery:

"
    $('#" + ModeOfTransportationDD.Id +"').find('option').each(function() 
    {
        var DropdownValue = $(this).val();
        var array = $('#" + DisableOptValues_Inpt.Id +"').val().split(',');

        $.each(array, function(i)
        {
            if (DropdownValue == array[i])
            {
                $('#" + ModeOfTransportationDD.Id +" option[value=' + DropdownValue + ']').attr('disabled','disabled');
            }
        });    
    });
"


I don't know what exact implementation flow you had followed in your approach but I would suggest you to refer the widget runtime Id instead of hard-coded Id value in the selector statement. 

Refer to the attached .oml file


I hope this helps you!


Kind regards,

Benjith Sam

DigitalLabDDDisableOptJS.oml

Hard-coded I'd I have mentioned for testing purpose in my code but originally I am using runtime Id.let me check tomorrow 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.