UIB AJAX call

Danie Biesiada1
Tera Contributor

Hi everyone,

I’m working on a technical dashboard in UIB that includes a client script. I have a simple requirement: retrieve all child project IDs for a given parent project.

I created a data resource and bound a client state parameter to the condition. However, when I try to access the returned IDs from the data resource in my client script, I’m getting nothing back — the data resource appears to return an empty object.

Has anyone run into this before or knows what I might be missing?
Thanks!

4 REPLIES 4

TariqueWasim
Tera Contributor

Can you share your script here.

Martin Virag
Mega Sage
Mega Sage

Things I would check:
1) did I add the execute ACL to the data source? You should see any data returned at the DS level when clicking on the data source
2) Use logging within the data resource script on the final return object to see what is passed over
3) Try a default client state parameter that you sure are working
4) Check the syntax on the client script, most stuff there works as an object (make a log to the console about the object (console.log works here))


Danie Biesiada1
Tera Contributor
const projectFilter = appliedFilters.find(f => f.label === "Project");
    const currPrjValue = projectFilter.values.toString() || "";




    // Update parentId state first
    api.setState("parentId", currPrjValue);


    // Explicitly refresh the data resource and handle the result
    api.data.child_projects.refresh();
  
    // Update parFilters state
    api.setState("parFilters", ({ currentValue }) => {
        const { parFilters, encodedQueries } = mergePARFiltersV2(
            currentValue,
            appliedFilters
        );
        api.setState("encodedQueries", encodedQueries);
        
        return parFilters;
    });

  api.data.child_projects.results does not return any value

okay, a couple of things. According to the documentation https://www.servicenow.com/docs/bundle/zurich-api-reference/page/app-store/dev_portal/API_reference/...

Make sure that the child projects data source has its "mutates server data" field set to false
second, its an asynchronous operation and its actually returns nothing (again from the documentation) 
It just refreshes the data source so if you want to access any data from it you hat to go with a simple json dotwalk like
let variable = api.data.child_projects.results.variablevalue <- this is just an example, the actual structure is something you should see in the data resource

hope this will help you narrowing down your issue