How to modify widget config programmatically?

2399
8
Jump to solution
09-24-2018 07:21 PM
PrashantKirpan
Occasional Contributor

Hi All,

I have created custom widget in WAB developer edition V2.9.

I want to change value programmatically in widget config. On run time I am able to set value using below code but does not update in config file. 

this.config.tempProperty = "Test" ;

If I refresh application then tempProperty still showing old value.

Is there any way to update widget config programatically?

Regards,

Prashant 

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Prashant,

  Sorry, I have now read you whole reply and see that you are attempting to set the config value inside the widget.js and NOT the settings.js. So the issue is that the widget.js does not have file system access to write to the widget json file. This can only be done in the widget settings.js which is run in NodeJS (which does have file system access). Having the client be able to write to a file on the server from code would be insane as the security implications of this would be tremendous.

View solution in original post

8 Replies
RobertScheitlin__GISP
MVP Emeritus

Prashant,

  How are you checking that the property is NOT updated? Which file are you checking?

0 Kudos
PrashantKirpan
Occasional Contributor

Hi Robert,

I am checking widget's config.json located inside "my custom widget" folder i.e.

C:\arcgis-web-appbuilder-2.9\WebAppBuilderForArcGIS\server\apps\5\widgets\MyWidget\config.JSON

I am reading json file through notepad++ or can see content using console.log(this.config).

To create custom widget, I am referring below tutorial.

https://developers.arcgis.com/web-appbuilder/sample-code/create-custom-in-panel-widget.htm

I trying to update property in widget.js, startup function and no settings file implemented for this widget. 

startup: function () {
this.inherited(arguments);

this.config.tempProperty = "Test" ;

}

Regards,

Prashant 

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Well that is your problem then. The config.json is just a template that is used when the widget is added to your app. When you add your widget this file is copied to the apps configs folder. You need to look in that folder.

0 Kudos
PrashantKirpan
Occasional Contributor

Hi Robert,

I have checked config file located in apps configs folder but still showing old value. I am looking into below path,

C:\arcgis-web-appbuilder-2.9\WebAppBuilderForArcGIS\server\apps\5\configs\MyWidget\config__5.json

Regards,

Prashant Kirpan

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Prashant,

  Sorry, I have now read you whole reply and see that you are attempting to set the config value inside the widget.js and NOT the settings.js. So the issue is that the widget.js does not have file system access to write to the widget json file. This can only be done in the widget settings.js which is run in NodeJS (which does have file system access). Having the client be able to write to a file on the server from code would be insane as the security implications of this would be tremendous.

PrashantKirpan
Occasional Contributor

Thanks Robert, It will really help me to resolve issue.

I am trying to create settings widget where admin user can set some settings(on run time) and other widgets will use this settings for

own business purpose.I can use Widget's data communication to receive data and store in settings.js. 

Just wanted to confirm, can I implement above scenario using settings.js? or could you please suggest any preferred way?


Regards,
Prashant

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Prashant,

   Again, the issue is that at runtime the widget is running on the client and does not have file system access to change a json file. The settings.js is only available when running the app in WAB Builder which is running NodeJS and has file system access. If you need a widget at runtime to set a setting in your app that another widget will use the you can have that widget set a windows global variable that the other widget will use or as you mentioned use widget communication to get that setting over to the other widget and that will work fine for the scope of that app, but it will not be persisted in the apps configs for use the next time that app is run.

PrashantKirpan
Occasional Contributor

Hi Robert,

Thanks for detail clarification. Really appreciate your help.

Regards,

Prashant

0 Kudos