The below posted code is a backend code. Please help me a sample front end code for retrieve any extended field. Thank You : )

import { contacts } from ‘wix-crm-backend’ ;

export function myQueryExtendedFieldsFunction ( ) {
return contacts . queryExtendedFields ()
. find ()
. then (( queryResults ) => {
const items = queryResults . items ;
const firstItem = items [ 0 ];
const pageSize = queryResults . pageSize ;
const hasNext = queryResults . hasNext ();
const hasPrev = queryResults . hasPrev ();
const length = queryResults . length ;
const query = queryResults . query ;

  **return**  items ; 
}) 
. **catch** (( error ) => { 
  console . error ( error ); 
}); 

}
For example I have created a Custom Field : SchoolName. How would I get / retrieve data of that Custom Field in a input field in another page? Kindly help

First generate a BACK-END-JSW-FILE, giving it the following name → “Contacts.jsw” —> Attention - - CASE-SENSITIVE!!!

  1. Put this CODE onto your BACKEND -Section…
import { contacts } from 'wix-crm-backend';

export function retrieveExtendedField(fieldKey) {
  return contacts.getExtendedField(fieldKey, {suppressAuth: true})
    .then((extendedField)=> {return extendedField;})
    .catch((error)=> {console.error(error);});
}
  1. Put this one onto your FRONTEND-section…
import { retrieveExtendedField } from 'backend/Contacts.jsw'

$w.onReady(()=>{
   $w('#myButton').onClick(()=>{retrieveExtendedField("SchoolName"); console.log();});
});

@russian-dima Thanks for your kind support and quick reply. : )
I am not able retrieve by this code. This is how I pasted and run your code in backend - contacts2.jsw. But I think having some issues. I have used a variable to retrieve data in an input field called - #aadhar and extendedField also having this name - aadhar. But unfortunately I am still not getting. Have I done something wrong. Plz have a look.

MY FRONTEND –
import { retrieveExtendedField } from ‘backend/contacts2.jsw’ ;

$w . onReady (() => {
$w ( ‘#retrieve’ ). onClick (() => {

    **let**  aadhar  =  retrieveExtendedField ( "aadhar" ); 
    $w ( '#aadhar' ). value  =  aadhar ; 

    console . log (); 
}); 

});


MY BACKEND - -
import { contacts } from ‘wix-crm-backend’ ;

export function retrieveExtendedField ( fieldKey ) {
return contacts . getExtendedField ( fieldKey , { suppressAuth : true })
. then (( extendedField ) => { return extendedField ; })
. catch (( error ) => { console . error ( error ); });
}

You marked my post with → BEST-ANSWER ← problem RESOLVED ???

Dear @russian-dima , I liked and marked just because after so much efforts someone gave me some hope. So, I just marked it in a hurry. I thought it would work like you are amoung the best. But, alas it didn’t work out for me. I am still nowhere. Please help.

@onlinesanawad
I will take a second look on it…

Here you even did a good job…

$w.onReady(() => {
    $w('#retrieve').onClick(() => {
        let aadhar = retrieveExtendedField("aadhar"); console.log("aadhar: ", aadhar);
        $w('#aadhar').value = aadhar; 
    });
});

You completed my incomplete code, the right way (almost)! Well done!

But why —> almost???

Because - → Async-Await is till missing!
You have to await for results from backend before you can show them.

$w.onReady(() => {
   $w('#retrieve').onClick(async() => {
     let aadhar = await retrieveExtendedField("aadhar"); console.log("aadhar: ", aadhar);
     $w('#aadhar').value = aadhar; 
   });
});

If you would use the console a little bit more, you would be able to solve your issue by your own!

USE MORE THE → CONSOLE!:wink:

Take a look at the last provided CODE and try to understand what was missing in my first provided INCOMPLETE code and in your improved (also not complete) code-version.

Open your CONSOLE and take a look onto results. Which results do you get?

@russian-dima No still not getting anythig.


Here is something : If i put “custom.aadhar” instead of null this happens… Kindly solve coz I think we are very near to solution. : )

These are to testing customFields/extendedFields are : Aadhar and Ironman
I am not able to get anything. : (

@onlinesanawad

More information about extended fields…

When accessing contact data, extended field values are available at extendedFields[key]. For example, if the key is " custom.notes" , the value can be accessed at extendedfields[" custom.notes "].
Once set, key cannot be modified, even if displayName changes.

Make clear what’s your correct fieldKey-ID, but how ???

Generate a little TEST-CODE, like…

$w.onReady(() => {
    let fieldKey1 = "aadhar";
    let fieldKey2 = "Aadhar";
    let fieldKey3 = "custom.aadhar";
    let fieldKey4 = "custom.Aadhar";
    //---------------------------------------------
    let fieldKey5 = "ironman";
    let fieldKey6 = "Ironman";
    let fieldKey7 = "custom.ironman";
    let fieldKey8 = "custom.Ironman";

    $w('#retrieve').onClick(async() => {
        let aadhar = await retrieveExtendedField(fieldKey1); 
        console.log("aadhar: ", aadhar);
        $w('#aadhar').value = aadhar; 
    });
});

You can see 8-different generated test-key-fields to test, which one will work of them. Test all 8 keyFields to find the right SYNTAX.

All you have to do is just to change → …
let aadhar = await retrieveExtendedField(fieldKey—>1 <----);
And run your test 8x!

Which one will work ?

@russian-dima Thanks a ton. I will try it for sure and get back to you with the results. Thanks again. : )

I got the console answer by fieldKey3 = “custom.aadhar”.


This input field is not getting anything. I done everything right as per your instruction. Kindly have a look once more.

Open the 3-dots —> {…} ← and take a look onto → RESULTS

Problem solved? If so → put all information together, POST your working FULL-CODE in a nicely CODE-BLOCK and mark it as → BEST-ANSWER

@russian-dima Problem is not solved let me get back to you with some explanations.

@onlinesanawad
Waiting for explanations…

BTW: Will connect this post for more reference and info…

@russian-dima I am really sorry for the delay in reply. I was not feeling well for few days. As I run this code you given still giving me NULL.

I have tried every possiblilty you given. One more thing that if I paste this code :
import { contacts } from ‘wix-crm-backend’ ;

export function myQueryExtendedFieldsFunction ( ) {
return contacts . queryExtendedFields ()
. find ()
. then (( queryResults ) => {
const items = queryResults . items ;
const firstItem = items [ 0 ];
const pageSize = queryResults . pageSize ;
const hasNext = queryResults . hasNext ();
const hasPrev = queryResults . hasPrev ();
const length = queryResults . length ;
const query = queryResults . query ;

  **return**  items ; 
}) 
. **catch** (( error ) => { 
  console . error ( error ); 
}); 

}


It easily provides extendedFields but I am not able to fetch data by any mean. Kindly Help.

Hit “Run” and the output will appear below

[backend/queryContacts.jsw, myQueryExtendedFieldsFunction] called

[backend/queryContacts.jsw, myQueryExtendedFieldsFunction] returned with

Array(17)
json Table Copy JSON

0:
{…}
json Table Copy JSON

_createdDate:

dataType:
“TEXT”

displayName:
“SchoolName”

fieldType:
“USER_DEFINED”

key:
“custom.schoolname”

namespace:
“custom”

_updatedDate:

Hi Sanawad, the getExtendedField function does not get you the data you are looking for. It only retrieves general information about the extended field, i.e. the name and the field key. Once you know the field key, you don’t need to run this function anymore. (But you’ll probably recognize the field key anyway)

To get the actual extended field data you can use one of two backend functions

  • contacts . getContact ( contactId , options ) using the contactId of the current user
  • or, if your extended field is also a custom info field for members, it can be retrieved through currentMember . getMember ({ fieldsets : [ ‘FULL’ ]})

The returned values contain the extended field data.

@verbaldancing Thank you so much for this precious information. I didn’t knew that I tried everything and possibly every code from previously asked questions. But I think due to many depreceated functions I was not able to get data. I request you if is it possible to have sample frontend code for that. I am trying my best after this info but If you could, It would be big help : )

You are welcome @onlinesanawad ! You can find a backend example here https://www.wix.com/velo/reference/wix-crm-backend/contacts/getcontact check the example, they are retrieving the contact. If you only want the extended fields, you could change ’return contact’ to ‘return contact.info.extendedFields’.