how to let one function executed ist then it should execute rest of code

qasimidl 106 Reputation points
2024-02-07T13:22:58.04+00:00

i am using jQuery to retrieve data from SharePoint. i have made one function. problem : my function does not executed completely, it goes ahead and rest of my code is executed first before my function code is executed completely . so its creating problem. Solution required: it should let my function completed ist then execute rest of code.. thanks

My code // my function var flager function Validate_IsUsr() { var clientContext = new SP.ClientContext.get_current(); var oList = clientContext.get_web().get_lists().getByTitle('Stg'); var camlQuery = new SP.CamlQuery(); camlQuery.set_viewXml('<View><Query><Where><And><Eq><FieldRef Name='ID'/>' + '<Value Type='number'>' + parseInt($("#ddlstg").val()) + '</Value></Eq><Eq><FieldRef Name='Flag'/>' + '<Value Type='number'>' + 1 + '</Value></Eq></And></Where></Query></View>'); this.collListItem = oList.getItems(camlQuery); clientContext.load(collListItem); clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceededIsSecpuser), Function.createDelegate(this, this.onQueryFailedIsSecpuser)); } function onQuerySucceededIsSecpuser(sender, args) { //var listItemInfo = 1 var listItemEnumerator = collListItem.getEnumerator(); while (listItemEnumerator.moveNext()) { var oListItem = listItemEnumerator.get_current(); $('#hid_Stg').val(oListItem.get_item('stg')); // return flager= oListItem.get_item('stg'); } } // calling above function like this function onsuccess() { // bind btns for secp or psx if ($("#hid_stg").val() == 1) { btns = Actionbtns(0); } else { Validate_IsUsr(); /// it should executed this function first then goes below. Currently, not executing like this.it goes below then finish "Validate_IsUsr" function if ($('#hid_stg').val()) btns = Actionbtnssp(0);

        }
        for (var i = 0; i <= itemCount - 1; i++) {
            var oListItem = oListItems.itemAt(i);
            statusNA = 1;
      }
```kindly provide solutions
}
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,810 questions
0 comments No comments
{count} votes