0

I have ListA and ListB.
ListA has fields with values ( Doc code[A1], Project number[008]) and ListB has fields (Project path[//bank.com], Project number[008]).
We have one dropdown and button in webpart. Dropdown is populated with doc code. As of now when we select doc code in DD and click on button it is fetching respective prj no. from ListA. now we want to fetch the prj path from ListB when doc code is selected in DD.
Like when A1 is selected in dropdown I should get value "//bank.com" as project number is foreign key and corresponding to value.

How to achive this via rest api, we have o365.

Thanks

0

Expecting that ListA 'PROJECTNUMBER' field is a lookup field in ListB.

First get 'DOCCODE' & 'ID' fields of the each item from ListA. Then on binding Dropdown use 'ID' field as value attribute.

It may look like this,

<select>
  <option value="1">A1</option>
  <option value="2">A2</option>
</select>

Now on the button click, you will get selected option value (selectedId). Then call GetProjectPath function,

function GetProjectPath(selectedId)
{
        getItems("/_api/Web/Lists/GetByTitle('ListB')/Items?$filter= PROJECTNUMBER/ID eq "+selectedId+"&$select=PROJECTPATH").done(function(data){
                console.log("NO.OF ITEMS: "+data.d.results.length);
                data.d.results.forEach(function(item){
                        var projectPath = item.PROJECTPATH;

                });
        });
}

function getItems(url){

    return $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + url,
        type: "GET",
        headers: {
            "accept": "application/json;odata=verbose",
        }
    });
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.