Aug 26 2022 11:50 PM
I have a field name called Security(choice field) and other field name is Sensitivity. I want to copy the values of Security in Sensitivity in the list view. For example if value of security is Internal then in sensitivity column also it should show Internal in the list view only irrespective of the values stored in sensitivity. In laymen term Both field should show same values. I am new in spfx environment. Please help. I am using react framework. Let me know if you need any other details.
Aug 27 2022 03:22 AM
Hi @LaxmikantB2
If you are using SPFx Field Customizer, then implement the onRenderCell with below logic
The method has signature as follows:
public onRenderCell(event: IFieldCustomizerCellEventParameters): void
Use below code to get the Security field value:
const securityValue = event.listItem["_values"].get("Security");
Once you get the item id, you can get the value of other field from same item.
Return the value as:
event.domElement.innerHTML = `<div>${securityValue}</div>`
Aug 27 2022 04:07 AM
Hello Nanddeep,
Thanks for your reply...
What Will be inside the "_Values"?
currently my code look like this in .ts file:
public onRenderCell(event: IFieldCustomizerCellEventParameters): void {
const securityValue = event.listItem["_values"].get("Security");
const conditionalFc: React.ReactElement<{}> =
React.createElement(ConditionalFc, { text } as IConditionalFcProps);
ReactDOM.render(conditionalFc, event.domElement);
}
And in component .tsx file
I am getting error as :
Element implicitly has an 'any' type because expression of type '"_values"' can't be used to index type 'ListItemAccessor'.
Property '_values' does not exist on type 'ListItemAccessor'.
Aug 30 2022 08:28 AM
Aug 30 2022 08:33 AM
Hi @LaxmikantB2
I will try to share the working code by coming Sunday. Bit away from laptop due to ongoing festive season. Sorry for that.
Sep 01 2022 07:41 AM
SolutionHi @LaxmikantB2
The below code should give you Security (choice column) value:
event.listItem["_values"].get("Security")
The result is as follows:
Please note, I am using SPFx v1.15.0
Sep 04 2022 10:59 PM
Hi @LaxmikantB2
Did you get chance to look at the code snippet? Is it working for you?
Sep 04 2022 11:27 PM
@NanddeepNachan
Still getting the same error:
Element implicitly has an 'any' type because expression of type '"_values"' can't be used to index type 'ListItemAccessor'.
Property '_values' does not exist on type 'ListItemAccessor'.
Sep 04 2022 11:55 PM
Hi @LaxmikantB2
I see that you are using Node version 16.16.0, instead can you try using 16.13.2?
Sep 01 2022 07:41 AM
SolutionHi @LaxmikantB2
The below code should give you Security (choice column) value:
event.listItem["_values"].get("Security")
The result is as follows:
Please note, I am using SPFx v1.15.0