0
votes

Alright, this one's got me seriously stumped, after trying things out for hours with the block of javascript below I'm still getting the same error in IE's javascript debugger.

The error I'm getting is SCRIPT5007: Unable to get value of the property 'get_id': object is null or undefined.

And below is my code:

AS.SP.ClientActions.ClientProgramEdit_Status = new AS.SP.ClientActions.ButtonStatus();
AS.SP.ClientActions.Can_ClientProgramEdit = function (groupID) {

var OnError = function (sender, args) {
    AS.SP.ClientActions.ClientProgramEdit_Status.enabled = false;
    RefreshCommandUI();
};

var items = AS.SP.ClientActions.GetSelectedItems();
var count = CountDictionary(items);
if (count === 1) {
    var itemID = items[0].id;
    if (AS.SP.ClientActions.ClientProgramEdit_Status.itemID != itemID) {
        AS.SP.ClientActions.ClientProgramEdit_Status.itemID = itemID;
        AS.SP.ClientActions.ClientProgramEdit_Status.enabled = false;

        AS.SP.ClientActions.GetUrl(function (rootUrl) {
            var fragments = AS.SP.Navigation.ParseUri(rootUrl);

            var ctx = new SP.ClientContext(fragments.path); 
            var web = ctx.get_web();
            var props = web.get_allProperties();

            ctx.load(web);
            ctx.load(props);
            ctx.executeQueryAsync(function () {

                var listId = 'Client Programs';
                var sdlist = web.get_lists().getByTitle(listId);

                var locationID = props.get_item('WL_ITEM_ID');
                var query = new SP.CamlQuery();
                query.set_viewXml('<View><Query><Where><And><Eq><FieldRef Name="len_cp_Location" /><Value Type="Text">' + locationID + '</Value></Eq><Eq><FieldRef Name="len_cp_Client_Status" /><Value Type="Text">Inactive</Value></Eq></And></Where></Query><ViewFields><FieldRef Name="Title" /></ViewFields></View>');
                var items = sdlist.getItems(query);
                ctx.load(items);
                ctx.executeQueryAsync(function () {
                    var item = items.itemAt(0);
                    var itemID = item.get_id();

                    if (itemID == "WL_ITEM_ID") {
                        AS.SP.ClientActions.ClientProgramEdit_Status.enabled = true;
                        RefreshCommandUI();
                    }
                }, OnError);
            }, OnError);
        });
    }
}

return AS.SP.ClientActions.ClientProgramEdit_Status.enabled;
}

My theory is that I've done something wrong with my CAML query but at this point I really don't know, any help with this would be greatly appreciated, thanks!

1
I should also explain that stepping through the code, itemID does seem to have a value, however once the debugger reaches the return it seems to lose the value, when I hover over itemID at this point it just says undefined.Him_Jalpert
So in the console if you manually look-up get_id does it confirm the function exists? What happens in other browsers (or, with this being for SharePoint, are you restricted to IE?)Mitya

1 Answers

0
votes

You are using the items variable twice, once on line 9:

var items = AS.SP.ClientActions.GetSelectedItems();

And again inside GetUrl:

var items = sdlist.getItems(query);

There is a name conflict in your execureQueryAsync closure. I would begin by fixing this issue. Which items collection do you want to reference? Do you mean to load the original items variable:

 ctx.load(items); 
 var items = sdlist.getItems(query);