I'm new to experience builder and I'm building a new project my question would be is it possible to create custom widget in experience builder that can read and fetch url parameters and then filter based on those parameters?
Solved! Go to Solution.
As it happens I've been working on a widget that does the first part of this pretty easily. I don't know what kind of source you might be using, but consider a method like this:
const getServiceUrl = (dataSourceId): Promise<string> => {
return new Promise((resolve) => {
const checkDataSourceManager = () => {
const dataSourceManager = DataSourceManager.getInstance();
if(dataSourceManager) {
const dataSourceArray = dataSourceManager.getDataSourcesAsArray();
const selectedDataSource = dataSourceArray.find(ds => ds.id === dataSourceId);
//const dataSrcJson = dataSourceManager.getDataSource(dataSourceId).getDataSourceJson();
const dataSrcJson = selectedDataSource.getDataSourceJson();
const dataSourceURL = dataSrcJson?.url + queryString;
resolve(dataSourceURL);
} else {
setTimeout(checkDataSourceManager, 100); // Check again after a short delay
}
};
checkDataSourceManager();
});
};
As it happens I've been working on a widget that does the first part of this pretty easily. I don't know what kind of source you might be using, but consider a method like this:
const getServiceUrl = (dataSourceId): Promise<string> => {
return new Promise((resolve) => {
const checkDataSourceManager = () => {
const dataSourceManager = DataSourceManager.getInstance();
if(dataSourceManager) {
const dataSourceArray = dataSourceManager.getDataSourcesAsArray();
const selectedDataSource = dataSourceArray.find(ds => ds.id === dataSourceId);
//const dataSrcJson = dataSourceManager.getDataSource(dataSourceId).getDataSourceJson();
const dataSrcJson = selectedDataSource.getDataSourceJson();
const dataSourceURL = dataSrcJson?.url + queryString;
resolve(dataSourceURL);
} else {
setTimeout(checkDataSourceManager, 100); // Check again after a short delay
}
};
checkDataSourceManager();
});
};
Thank you for your help 🙂
If you are looking to get an arbitrary URL parameter, not necessarily a data source. You could use URLSearchParams.
Full explanation with a starter widget and an example using it to start a query here, along with many more Experience Builder tips.