PickList : how to clear the cache ?

Hello,

I’m looking for a way or turnaround for clearing the cache of a PickList constructed by a DataSource of a SelectItem.
How could this be done ?

Any help or insight would be appreciated.
Thank you

SmartClient 7 RC2

{name: "577069969", title: "Site", type: "select", required: true, startRow: true, endRow: true, colSpan: "*",pickListWidth: 400
   ,autoFetchDisplayMap: false
   ,autoFetchData: false
   ,valueField: "key", displayField: "name"
   ,setValue: function (newValue) {
       this.Super("setValue", [newValue]);
       // *** CLEAR CACHE ***
   }
   ,fetchMissingValues: false
   ,optionDataSource: isc.DataSource.create({
       showPrompt: false,
       dataFormat: "xml",
       dataURL: isc.Page.cp + "plugins/UISelectHandler?cell=577069969&vid=-1309238938&rowid=18",
       recordXPath: "//value",
       fields: {
           key: {valueXPath:"@key", title:"key", primaryKey:true, name:"key"},
           name: {valueXPath:"@label", title:"name", name:"name"}
           , X2d31373139373031393838: {valueXPath:"X2d31373139373031393838", title:"Site", name:"X2d31373139373031393838"}
           , X2d3533373830363836: {valueXPath:"X2d3533373830363836", title:"Société", name:"X2d3533373830363836"}
       }
   })
   ,pickListFields: [
       {name: "X2d31373139373031393838"},
       {name: "X2d3533373830363836"}
   ]
   ,defaultValue: 22
   , valueMap: {
       985 : "Bureaux DSI"
       ,22 : "Branche Raffinage & Marketing"
       ,794 : "Holding Total"

   }
}

See the docs - calling fetchData() forces a fetch. However that’s an incorrect call to Super() (see the docs - “arguments” is always required) and it probably does not make sense to fetch on every setValue call.

You are most likely headed down the wrong path. For advice on your overall approach, describe what you’re trying to do from the end user’s perspective.

The call to Super was an error in my code. (The override of setValue is an example for a point of entry to clear the cache). here it is, corrected :

,setValue: function (newValue) {
    this.Super("setValue", arguments);
   // CLEAR PICKLIST DATA CACHE 
   ...
}

What I need is to clear the data cache of the ‘picklist’ when the ‘SelectItem’ value is changed.
So that I can obtain a new set of values.

Thank you

See our previous post (it doesn’t seem like you read it?)

oups!

Hello,

I was so distressed with the idea of having an error in my code that i didn’t read well all the post :slight_smile:

1/ So the idea is that I have a SelectItem in a form. According to some user interaction, I have to change the value and valueMap; and, by consequence, the ‘PickList’ data must be refetched.
(the real case is that the values in the ‘SelectItem’ depend on the value of another item and i need to modify the ‘SelectItem’ everytime the ‘source’ item is changed)
I have several fields in my ‘PickList’ (like the ‘List - Related Records’ feature explorer’s example)

The purpose of my post was to empty the cache so that the ‘PickList’ data is refetched when the user opens the ‘PickList’ again. And not get it everytime which is what happens when using ‘fetchData’.

I can’t set autoFetchData to true since I don’t want to get the PickList data unless the user opens the list.

So is there a way to empty the data of the ‘PickList’ without calling ‘fetchData’ ? and therefore having the data fetched the next time the user opens the list ?
I tried setting the 'SelectItem’s property ‘cachePickListResults’ to false but it doesn’t change anything.
Thank you for any insight on what could be done in this case.

Here is the example :
A Form with a selectItem, and a button to test the change in values of the SelectItem

isc.setAutoDraw(true);
var index = 0;
function getDataUrl () {
	if (index == 0)
		return "./data/projets1.xml";
	else
		return "./data/projets2.xml";
}
function setNewValues () {
	var newValue = 8;
	var newValueMap = { "9": "construire", "8": "redresser"};
	var item = form.getItem ("1456763482");
	//alert (item.
	
	item.setValueMap (newValueMap);
	item.setValue (newValue);
	
	index++;
	item.optionDataSource.dataURL = getDataUrl ();
	item.fetchData (
	//	function (item, dsResponse) {
	//		item.setValueMap (newValueMap);
	//	}
	);
// CLEAR THE PICK LIST CACHE INSTEAD OF CALLING FETCH DATA


}
isc.DynamicForm.create({
			ID: "form",
            numCols: 4*2,
            fields: [
            {name: "1456763482", title: "Projet", type: "select", required: true, startRow: false, endRow: false,pickListWidth: 400
			,addUnknownValues: false
        ,setValue: function (newValue) {
            this.Super ("setValue", arguments);
        }
        ,setValueMap: function (newValue) {
            this.Super ("setValueMap", arguments);
            this.fetchData ();
        }
        ,autoFetchDisplayMap: false
        ,autoFetchData: false
        ,valueField: "key", displayField: "name"
        ,optionDataSource: isc.DataSource.create({
            showPrompt: false,
            dataFormat: "xml",
            dataURL: getDataUrl (),
            recordXPath: "//value",
            fields: {
                key: {valueXPath:"@key", title:"key", primaryKey:true, name:"key"},
                name: {valueXPath:"@label", title:"name", name:"name"}
                
                    , X31333134353430333034: {valueXPath:"X31333134353430333034", title:"Projet", name:"X31333134353430333034"}
                
                    , X32303133313935323831: {valueXPath:"X32303133313935323831", title:"Chantier", name:"X32303133313935323831"}
                
            }
        })
        ,pickListFields: [
            
                {name: "X31333134353430333034"}
            ,
                {name: "X32303133313935323831"}
            
        ]
     
                ,defaultValue: "1"
            
        , valueMap: {
        "1" : "Achat"
        ,"10" : "Achat Spécifique"
        ,"12" : "I.T. Spécifique"
        ,"2" : "Logistique"
        ,"13" : "Logistique Spécifique"
        ,"6" : "Relation Client"
        ,"7" : "Ressources Humaines"
        ,"5" : "Structure et frais généraux"
        ,"3" : "Vente et marketing"
        ,"11" : "Vente et marketing Spécifique"
        
        }
    
        }

        ]
        });
		
isc.Button.create ({
	top: 300, title: "test",
	click: function () {
		setNewValues ();
	}
})

projets1.xml

<values uuid="cb50516e"><value key="13" label="Logistique Spécifique"><X31333134353430333034 name="projet">Logistique Spécifique</X31333134353430333034><X32303133313935323831 name="chantier">économie</X32303133313935323831></value><value key="12" label="I.T. Spécifique"><X31333134353430333034 name="projet">I.T. Spécifique</X31333134353430333034><X32303133313935323831 name="chantier">économie</X32303133313935323831></value><value key="11" label="Vente et marketing Spécifique"><X31333134353430333034 name="projet">Vente et marketing Spécifique</X31333134353430333034><X32303133313935323831 name="chantier">économie</X32303133313935323831></value><value key="10" label="Achat Spécifique"><X31333134353430333034 name="projet">Achat Spécifique</X31333134353430333034><X32303133313935323831 name="chantier">économie</X32303133313935323831></value><value key="7" label="Ressources Humaines"><X31333134353430333034 name="projet">Ressources Humaines</X31333134353430333034><X32303133313935323831 name="chantier">économie</X32303133313935323831></value><value key="6" label="Relation Client"><X31333134353430333034 name="projet">Relation Client</X31333134353430333034><X32303133313935323831 name="chantier">économie</X32303133313935323831></value><value key="5" label="Structure et frais généraux"><X31333134353430333034 name="projet">Structure et frais généraux</X31333134353430333034><X32303133313935323831 name="chantier">économie</X32303133313935323831></value><value key="3" label="Vente et marketing"><X31333134353430333034 name="projet">Vente et marketing</X31333134353430333034><X32303133313935323831 name="chantier">économie</X32303133313935323831></value><value key="2" label="Logistique"><X31333134353430333034 name="projet">Logistique</X31333134353430333034><X32303133313935323831 name="chantier">économie</X32303133313935323831></value><value key="1" label="Achat"><X31333134353430333034 name="projet">Achat</X31333134353430333034><X32303133313935323831 name="chantier">économie</X32303133313935323831></value></values>

projets2.xml

<values uuid="6d4029e1"><value key="9" label="construire"><X31333134353430333034 name="projet">construire</X31333134353430333034><X32303133313935323831 name="chantier">redresser et construire</X32303133313935323831></value><value key="8" label="redresser"><X31333134353430333034 name="projet">redresser</X31333134353430333034><X32303133313935323831 name="chantier">redresser et construire</X32303133313935323831></value></values>

2/ On the same point, while trying with ‘fetchData’, it’s working OK, but I have a problem.
On click of the button, I get an error"
this.formItem is undefined
,isc.A.$315=function(_1,_2,_3,_4,_5){if(…formItem.formatPickListValue(_1,_6,_2)}
"
which I managed to track to the PickListMenu class in ‘ISC_Forms.js’

This happens when I open the PickList of the Item before changing the values (ie clicking the button).
If I do not open the picklist before, I don’t get the error

If I don’t set the valueMap, I don’t have the error.
so I tried setting the ‘valueMap’ : before or after the fetch and even in the fetchData callback but I have the error everytime.

I need to set the ValueMap becuase I need to show the correct value of the item even when the PickList is not opened and its data fetched.

There are already examples for doing dependent selects in both grids and forms. Probably want to throw away your attempts and follow those samples.