0

I am trying to set the value of a multi lookup field. I am rendering my field using CSR and using registerGetValueCallback to get the value of my lookup field. But the value of my field does not update. I get no errors, neither in the UI nor the ULS log.

Here's what I have tried:

Register Callback:

if (modeNewEdit) {
    let valueCallback = $.proxy(
        () => {
            return ChildContracts.arrayToFieldValue(this.childContracts);
        }, this);

    formCtx.registerGetValueCallback(formCtx.fieldName, valueCallback);
}

arrayToFieldValue (Version 1):

public static arrayToFieldValue(contracts: IChildContract[]) {
    let value: string = "";

    if (contracts.length > 0) {

        contracts.forEach((c) => {
            value = value + c.id.toString() + ";#" + c.title + ";#";
        });

        value = value.slice(0, value.length - 2);
    }

    return value;
}

arrayToFieldValue (Version 2):

public static arrayToFieldValue(contracts: IChildContract[]) {
    let value = [];

    if (contracts.length > 0) {

        contracts.forEach((c) => {
            let val = new SP.FieldLookupValue();
            val.set_lookupId(c.id);
            value.push(val);
        });
    }

    return value;
}

I think the problem lies with the fact that my list item has a title field, but that field contains no value. The title value is set later in an ItemAdded ER. So I have tried Version 2 where I can only specify lookup id, but the result is the same. My multi lookup column isn't populated with any value and I get no error whatsoever. So can anybody shed some light on this?

2 Answers 2

1

Great to hear you solved it..

FYI, since you have TypeScript in your question/tags

this:

let value = [];
if (contracts.length > 0) {
    contracts.forEach((c) => {
        let val = new SP.FieldLookupValue();
        val.set_lookupId(c.id);
        value.push(val);
    });
}
return value;

can be written as:

return contracts.map( c => {
    let val = new SP.FieldLookupValue();
    val.set_lookupId(c.id);
    return val;
});
0

Ok, once again I can answer my own question. It turns out that SharePoint will only set multi lookup values if the corresponding lookup item's lookup column value is set. So my problem was indeed the missing title field value. After setting a dummy value for this field in ItemAdding, Version 2 works perfectly.

Strangely, this doesn't seem to be an issue if I use the server object model.

Your Answer

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

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