Skuid In-Line Snippet doesn’t work sometimes

I have created a in-line snippet and moved the changes to Prod successfully. But the problem is sometimes that snippet works sometimes doesn’t. Only when it starts to work if I make some changes to the code anywhere like console.log or alert to check if the snippet is loaded and working or not.

Prateek, I don’t completely understand this. Can you confirm wehther the snippet type is “In-line (Snippet)” or merely “In-line”.

If is “In-line (Snippet)” - it will only run when called by some action on the page, if it is merely “In-line” it will execute as it is processed when the page is built.

I usually add random console output to my snippet to ensure that it is actually executing.

Does that help? I’m not sure what you mean about making changes to the code…

(function(skuid) {
    var $ = skuid.$;
    var isClick = false;
    var activateHandler = function() {
        skuid.$("#bodyTable .nx-conditioncontainer-left .nx-conditiontoken.nx-actionselect .nx-actionselect-arrow").on("click", function() {
            setTimeout(function() {
                skuid.$("#bodyTable .nx-conditioncontainer-left .nx-actionselect-dropdown .nx-actionselect-dropdown-item").on("click", function() {

                    if (this.innerHTML === '** All Years') {
                        isClick = true;
                    } else {
                        isClick = false;

        if (isClick === false) {

            skuid.$("#bodyTable").ready(function() {
                var models = skuid.model.getModelList();
                var AcademicYearsModel = skuid.$M('AcademicYears').getFirstRow();
                var filterItems = [];
                $.each(, function(i, pe) {
                $.each(models, function(i, model) {
                    var modelAcademicYearCondition = model.getConditionByName('Academic_Year__c');
                    var modelAcademicYearPicklistCondition = model.getConditionByName('Academic_Year_Picklist__c');
                    if (modelAcademicYearCondition !== undefined && modelAcademicYearPicklistCondition !== undefined) {
                        model.setCondition(modelAcademicYearPicklistCondition, filterItems);



    $(document.body).one('pageload', activateHandler);"models.loaded", activateHandler);

Here’s the in-line snippet, Whenever a user selects ** All Years from the dropdown then I don’t want to run the default to Latest AY logic. So, this works for me but sometimes entire snippet doesn’t runs. And if I randomly add alert(‘something’) or console.log(‘something’); then it starts working. Not sure why this is happening.

So… your snippet is loading on page load and is constantly listening particular click events that correspond to particular HTML values. This is going to be pretty fragile.

We’d recommend using the model action mechanisms to fire the snippet explicitly. One of the triggering possibilities for model actions is “update row” - you can choose which field update triggers the action. The action would be to run the snippet.

Though as I look at your code - I think you can do all this declaratively. When the field is updated - run a sequence. Add a branch action if the value is “all years” and deactivate the specific year condition. Otherwize pass the year selected into that condition. Then query your data.

Let me know if this helps.

1 Like