Use Widget Value in Server Script - google-app-maker

I may be overthinking this drastically, but what is the easiest way to access a widget's value in a server script?
In my particular case, I am trying to use a dropdown widget's value as the filter for a calculated model query.
function getMonthlyTotalsByResource_() {
var allRecordsQuery = app.models.Allocations.newQuery();
allRecordsQuery.filters.Approved._equals = true;
allRecordsQuery.filters.Resource.Manager.ManagerName._equals = /* How do I make the widget's value available here? */
var allRecords = allRecordsQuery.run();
...
...

In your calculated model datasource in the server script have the following:
return getMonthlyTotalsByResource_(query);
Still in your model datasource add a parameter ('String?') and call it ManagerName.
On your page with the dropdown bind the value of the widget to #datasource.properties.ManagerName
In your server script function change to the following:
function getMonthlyTotalsByResource_(query) {
var allRecordsQuery = app.models.Allocations.newQuery();
allRecordsQuery.filters.Approved._equals = true;
allRecordsQuery.filters.Resource.Manager.ManagerName._equals =
query.parameters.ManagerName;
var allRecords = allRecordsQuery.run();

The easiest way to do this is to add a parameter to the datasource of your calculated model. Then bind something to it from the client side (e.g. bind to datasource.mycalculatedds.parameters.myparam ).
Then pass the default 'query' object from your calculated datasource. For example in your calculated DS, where you call your function, call
getMonthlyTotalsByResource_(query). Then you can set something like
var thismanager = query.parameters.myparam

// get widget value
function getWidgetValue() {
var val = app.PAGES.YOUR_PAGE.descendants.WIDGET_NAME.value;
return val;
}
// execture query
function getMonthlyTotalsByResource_(widgetValue) {
var allRecordsQuery = app.models.Allocations.newQuery();
allRecordsQuery.filters.Approved._equals = true;
allRecordsQuery.filters.Resource.Manager.ManagerName._equals = widgetValue;
var allRecords = allRecordsQuery.run();
}
// run
getMonthlyTotalsByResource_(getWidgetValue);

Related

i added a list box in asp.net , i need to get the option set values from ms crm to list box

I am new to ASP.Net I added a list box in asp.net , I need to get the option set values from ms crm to list box
I don't know how to return the value for this can anybody help me
public static string GetMtefrecord()
{
var service = CRMWrapper.GetCRMService();
RetrieveEntityRequest retrieveBankAccountEntityRequest = new RetrieveEntityRequest
{
EntityFilters = EntityFilters.Entity,
LogicalName = "tec_new_mtfmtir",
};
RetrieveEntityResponse retrieveBankAccountEntityResponse = (RetrieveEntityResponse)service.Execute(retrieveBankAccountEntityRequest);
//return retrieveBankAccountEntityResponse.LogicalName.ToString();
}
If your optionset is a global optionset, you can retrieve it using the RetrieveOptionSetRequest message. Here is a bit of sample code
RetrieveOptionSetRequest retrieveOptionSetRequest =
new RetrieveOptionSetRequest
{
Name = _globalOptionSetName //Put your optionsetname here
};
// Execute the request.
RetrieveOptionSetResponse retrieveOptionSetResponse =
(RetrieveOptionSetResponse)_serviceProxy.Execute(
retrieveOptionSetRequest);
OptionMetadata[] optionList =
((OptionSetMetadata) retrieveOptionSetResponse.OptionSetMetadata).Options.ToArray();

Flex Advanced Data Grid w/ hierarchical data: How to access currentTarget fields on dragdrop event?

So this is driving me crazy. I've got an advanced data grid with a dataprovider that's an array collection w/ hierarchical data. Each object (including the children) has an id field. I'm trying to drag and drop data from within the ADG. When this happens, I need to grab the id off the drop target and change the dragged object's parentid field. Here's what I've got:
public function topAccountsGrid_dragDropHandler(event:DragEvent):void{
//In this function, you need to make the move, update the field in salesforce, and refresh the salesforce data...
if(checkActivateAccountManageMode.selected == true) {
var dragObj:Array = event.dragSource.dataForFormat("treeDataGridItems") as Array;
var newParentId:String = event.currentTarget['Id'];
dragObj[0].ParentId = newParentId;
} else {
return;
}
app.wrapper.save(dragObj[0],
new mx.rpc.Responder(
function():void {
refreshData();
},
function():void{_status = "apex error!";}
)
);
}
I can access the data I'm draggin (hence changing parentId) but not the currentTarget. I think the hierarchical data is part of the problem, but I can't find much in the documentation? Any thoughts?
event.currentTarget is not a node, it's the ADG itself. However, it's quite easy to get the information you want, since the ADG stores that data internally (as mx_internal).
I'm using the following code snippets (tested with Flex SDK 4.1) in a dragOver handler, but I guess it will work in a dragDrop handler too.
protected function myGrid_dragDropHandler(event:DragEvent):void
{
// Get the dragged items. This could either be an Array, a Vector or NULL.
var draggedItems:Object = getDraggedItems(event.dragSource);
if (!draggedItems)
return;
// That's our ADG where the event handler is registered.
var dropTarget:AdvancedDataGrid = AdvancedDataGrid(event.currentTarget);
// Get the internal information about the dropTarget from the ADG.
var dropData:Object = mx_internal::dropTarget._dropData;
// In case the dataProvider is hierarchical, get the internal hierarchicalData aka rootModel.
var hierarchicalData:IHierarchicalData = dropTarget.mx_internal::_rootModel;
var targetParent:Object = null;
// If it's a hierarchical data structure and the dropData could be retrieved
// then get the parent node to which the draggedItems are going to be added.
if (hierarchicalData && dropData)
targetParent = dropData.parent;
for each (var draggedItem:Object in draggedItems)
{
// do something with the draggedItem
}
}
protected function getDraggedItems(dragSource:DragSource):Object
{
if (dragSource.hasFormat("treeDataGridItems"))
return dragSource.dataForFormat("treeDataGridItems") as Array;
if (dragSource.hasFormat("items"))
return dragSource.dataForFormat("items") as Array;
if (dragSource.hasFormat("itemsByIndex"))
return dragSource.dataForFormat("itemsByIndex") as Vector.<Object>;
return null;
}
var dropData:Object = mx_internal::dropTarget._dropData;
should be
var dropData:Object = dropTarget.mx_internal::_dropData;
Try this.

Combine/merge Dynamic Objects in AS3

I have 2 dynamic objects and I want to build one to contain all the properties:
var o1:Object = {prop1:val1,prop2:val2,prop3:val3};
var o2:Object = {prop3:val3a,prop4:val4};
and I need to obtain a third object that looks like that:
{prop1:val1, prop2:val2, prop3:val3a, prop4:val4};
Basically I need a way to iterate through the object properties and to add new properties to the third object. I have to mention I'm quite new to AS3/Flash/Flex.
First question, do you really mean to have prop3 in both objects? you will need to decide what to do in case of a collision like that, which object has precedence.
Secondly, check out the introspection apis: http://livedocs.adobe.com/flex/3/html/help.html?content=usingas_8.html
something like this should work:
public function mergeDynamicObjects ( objectA:Object, objectB:Object ) : Object
{
var objectC:Object = new Object();
var p:String;
for (p in objectA) {
objectC[p] = objectA[p];
}
for (p in objectB) {
objectC[p] = objectB[p];
}
return objectC;
}
If the property exists in A and B, B's will overwrite A's. Also note that if the values of a property is an object, it will pass a reference, not a copy of the value. You might need to clone the object in those cases, depending on your needs.
Note: I haven't actually tested the above, but it should be close. Let me know if it doesn't work.
Updated to fix the errors. Glad it works for you though.
You can dynamically access/set properties on objects with the index operator. The for loop will itterate over the property names, so if you put it all together, the following test passes:
[Test]
public function merge_objects():void {
var o1:Object = {prop1:"one", prop2:"two", prop3:"three"};
var o2:Object = {prop3:"threeA", prop4:"four"};
var o3:Object = new Object();
for (var prop in o1) o3[prop] = o1[prop];
for (var prop in o2) o3[prop] = o2[prop];
assertThat(o3.prop1, equalTo("one"));
assertThat(o3.prop2, equalTo("two"));
assertThat(o3.prop3, equalTo("threeA"));
assertThat(o3.prop4, equalTo("four"));
}
you can iterate over the object properties like:
var obj1:Object = new Object();
for(var str:String in obj2){
obj1[str] = "any value"; // insert the property from obj2 to obj1
}

How to increment a global variable inside a function?

The variable currentIndex is declared globally and initialized with a certain value say '0'. How do I hold the value of currentIndex which is incremented every time the function is called? In the given code, every time the function is called, the value is reinitialized.
function nextSong(e:Event):void
{
sc.stop();
currentIndex = currentIndex + 1;
var nextSongFunc:URLRequest = new URLRequest(songlist[currentIndex].file);
var nextTitle:Sound = new Sound();
nextTitle.load(nextSongFunc);
currentSound = nextTitle;
sc = currentSound.play();
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}
NextBtn.addEventListener(MouseEvent.CLICK, nextSong);
You need to declare the variable outside the function. How you do this depends on the context. Where is this function being defined? In the 'actions window' on the timeline in Flash? or inside a <script> block in Flex? or somewhere else?
It looks like you're in the Flash tool, in the actions window. If so, then just do it like this:
var currentIndex:int = 0;
function nextSong(e:Event):void {
sc.stop();
currentIndex = currentIndex + 1;
var nextSongFunc:URLRequest = new URLRequest(songlist[currentIndex].file);
var nextTitle:Sound = new Sound();
nextTitle.load(nextSongFunc);
currentSound = nextTitle;
sc = currentSound.play();
sc.addEventListener(Event.SOUND_COMPLETE, nextSong);
}
NextBtn.addEventListener(MouseEvent.CLICK, nextSong);
If that doesn't work, let me know some more details, and we'll sort it out.
If you're using Flash CS , you should take advantage of the DocumentClass. In such case you could define currentIndex as a private variable and it will be incremented/decremented in your functions.
This is a much better approach than writing your code in the Actions panel, allows for a lot more flexibility and you don't run into problems due to frame dependent code.

Flex: Passing data to a php file under some condition

I am using an accordian in which has three childs. Each child has some textInput elements. Now, i want to send data written in currently selected accordian's child's textInputs.
I have created a function "configure" which is called when someone clicks a button. That function checks as to which child of accordian is selected. Whichever is selected, the textInputs' text of that child are stored in locally defined variables.
Now, i have no idea how to pass these variable to the HTTPService i am sending at the end of function configure.
Can anyone tell me what should i do now or if there is any other efficient solution?
Thankyou
Codes:
private function configure():void
{
var selectedAlgos:Array = algosList.selectedItems;
var selectedMode:Array;
if (modeAccordian.selectedIndex == 0)
{
var N_interface:String = N_interface.text;
var N_duration:String = N_duration.text;
selectedMode.push(N_interface);
selectedMode.push(N_duration);
}
else if (modeAccordian.selectedIndex == 1)
{
var F_filePath:String = F_filePath.text;
var F_filePrefix:String = F_filePrefix.text;
}
else if (modeAccordian.selectedIndex == 2)
{
var T_filePath:String = T_filePath.text;
var T_filePrefix:String = T_filePrefix.text;
var T_metaFile:String = T_metaFile.text;
var T_toMergeFile:String = T_toMergeFile.text;
var T_NAT:String = T_NAT.text;
var T_NATIP:String = T_NATIP.text;
}
configureService.send();
}
HTTPService:
<mx:HTTPService id="configureService" url="configure.php" resultFormat="object" method="POST">
<mx:request xmlns="">
<selectedAlgos>{selectedAlgos}</selectedAlgos>
<selectedMode>{selectedMode}</selectedMode>
</mx:request>
</mx:HTTPService>
According to the HTTPService docs:
public function send(parameters:Object = null):mx.rpc:AsyncToken
parameters:Object (default = null)
An Object containing name-value pairs or an XML object,
depending on the content type for service requests.
So I believe you can drop the mx:request section of your mxml, and just add this to the send request:
configureService.send(
{
selectedAlgos:selectedAlgos.join(","),
selectedMode:selectedMode.join(",")
}
);
Otherwise, if you want to use binding, you should make the selectedAlgos/selectedMode bindable members of the same class that configure is defined in.

Resources