0

I have used the code from https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/react-list-form.

Based on the code above, I need add additional condition.

The code below I can get listId, and URL information. So I would like to pass another condition if the list contain field let say internal name = 'Category' otherwise pass null value. I thought I can do is fieldsSchema[i].InternalName = 'Category' ?? null.

let dt = await.listFormService.getFieldOptions(
    fieldSchema[i].LookupListId,
    this.props.webUrl,
    this.props.filterParam, //I need to check here if list contain field internal name = category
    this.props.filterValue
);

In this section I need add condition if list contain field with Internal name =' category and I need to construct the code i.e

const endpoint = `${webUrl}/_api/Web/lists/getbyid('${listId}')/items?&$filter=filterParam eq 'Blue'&$top=5000`; 

otherwise,

const endpoint = ${webUrl}/_api/Web/lists/getbyid('${listId}')/items?$top=5000;

public async getfieldOptions(listId: any, webUrl: string, filterParam: string, filterValue: string): Promise<any[]> {

        const endpoint = `${webUrl}/_api/Web/lists/getbyid('${listId}')/items?$top=5000`;


        try {
            let resp: SPHttpClientResponse = await this.spHttpClient.get(endpoint, SPHttpClient.configurations.v1);
            if (resp.ok) {
                let json = await resp.json();
                return json.value;
            }
        }
        catch (error) {
            console.error(error);
        }
        return [];

    }

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.