I'm using the Acumatica PXDatabase.Update method to update records in an Acumatica instance. The code I have is as follows, updating two fields and using another two as restrictors:
PXDatabase.Update<xTACProjectTask>(new PXDataFieldAssign<xTACProjectTask.dueDate>(tmpRow.Cells[indexMap["Due Date"]].Value.ToString())
, new PXDataFieldAssign<xTACProjectTask.startDate>(tmpRow.Cells[indexMap["Start Date"]].Value.ToString())
, new PXDataFieldRestrict<xTACProjectTask.projectID>(tmpRow.Cells[indexMap["TAC Project ID"]].Value.ToString())
, new PXDataFieldRestrict<xTACProjectTask.taskCD>(tmpRow.Cells[indexMap["TAC Task ID"]].Value.ToString()));
The PXDatabase.Update command uses a PXDataFieldParam array that contains the PXDataFieldAssign and PXDataFieldRestrict parameters, and the example above creates new instances of those inside the PXDatabase.Update method - but I'd like to find a way to declare the PXDataFieldParam object first and then conditionally add the PXDataFieldAssign objects to it, and finally passing that PXDataFieldParam array to the method.
I'd like to declare it something like this, but I can't seem to find the proper way:
PXDataFieldParam[] pfp = **????**;
PXDataFieldParam pf;
pf = new PXDataFieldAssign<xTACProjectTask.dueDate>(tmpRow.Cells[indexMap["Due Date"]].Value.ToString());
pfp.Append(pf);
pf = new PXDataFieldAssign<xTACProjectTask.startDate>(tmpRow.Cells[indexMap["Start Date"]].Value.ToString());
pfp.Append(pf);
pf = new PXDataFieldRestrict<xTACProjectTask.projectID>(tmpRow.Cells[indexMap["TAC Project ID"]].Value.ToString());
pfp.Append(pf);
pf = new PXDataFieldRestrict<xTACProjectTask.taskCD>(tmpRow.Cells[indexMap["TAC Task ID"]].Value.ToString());
pfp.Append(pf);
PXDatabase.Update<xTACProjectTask>(pfp);
Is there any way to do this?
Instead of defining an array of PXDataFieldParam why don't you define a List and then use the method .ToArray() when calling the PXDatabase.Update method.
PXDataFieldParam pf = null;
List<PXDataFieldParam> dbParams = new List<PXDataFieldParam>();
pf = new PXDataFieldAssign<SOLine.orderDate>(Accessinfo.BusinessDate);
dbParams.Add(pf);
PXDatabase.Update<SOLine>(dbParams.ToArray());
Related
I have code that sets the PXDataFieldAssign value as follows:
pf = new PXDataFieldAssign<xTACProjectTask.dueDate>(someValue);
I also have a table, holding the DAC field names, such as "xTACProjectTask.dueDate". This table also has a checkbox field to determine whether to use this DAC field as a parameter.
Is there a way to not have the DAC fieldname hard-coded, and instead (maybe using a 'typeof' call?) use the results of the table query to set that field name - like the following?
pf = new PXDataFieldAssign<typeof("xTACProjectTask.dueDate")>(someValue);
or, using my query result:
pf = new PXDataFieldAssign<typeof(query.value)>(someValue);
with query.value being the value in the table holding the DAC field name?
You can create it using Type.GetType and Activator.CreateInstance. Please see the example below:
string typeName = "PX.Objects.IN.InventoryItem+descr,PX.Objects";
Type typeArgument = Type.GetType(typeName);
Type genericClass = typeof(PXDataFieldAssign<>);
Type constructedClass = genericClass.MakeGenericType(typeArgument);
object created = Activator.CreateInstance(constructedClass,new object[] { "Test Description" });
You will get the below wrapped into object in the created
We are trying to add table within another table cell using only office api from the document editor plugin. We tried to find out various methods like using Range, Run Command, ParagraphAddDrawing, AddElement etc. to do it , but are unable to find a way to achieve it.
Please advice us an proper way to achieve this using API as early as possible...
Regards
You need to get cell and use method Push() on it.
Example:
var oDocument = Api.GetDocument(); // getting document object
var oParagraph, oTable, oCell; // init variables
oTable = Api.CreateTable(3, 3); // creating new table object
oCell = oTable.GetRow(0).GetCell(0); //getting first cell in first row
oDocument.Push(oTable); // Push new table to document
oTable_two = Api.CreateTable(3, 3); // creating second table object
oParagraph = oCell.GetContent().Push(oTable_two); // pushing new table to first table
How can I access the details element of a collection entity which is inside one section of another entity with openxava? For example, in the view of entity A, we have section {S1,S2,S3} and inside section S3 view, we have {collection of entity B}. Now I want to access the detail element of entity B, so that i can fill the element in an action controller. How do I do that?
Get the collection directly from the view, in this way:
Collection myCollection = getView().getSubview("myCollection").getCollectionObjects();
It must work even with oldest OpenXava versions
Obtain the entity associated to the view and get the collection from it. Since OpenXava 4.3 you can do it in this way:
MyEntity myEntity = (MyEntity) getView().getEntity();
Collection myCollection = myEntity.getMyCollection();
If you're using an OX previous to 4.3 do it in this way:
Map keyValues = getView().getKeyValuesWithValue();
if (!keyValues.isEmpty()) {
MyEntity myEntity = (MyEntity)
MapFacade.findEntity(getView().getModelName(), keyValues);
Collection myCollection = myEntity.getMyCollection();
}
You can do it in several ways. Here you have one, I have used it with some references that I want to modify from inside of an action called by the base module (which should work with your collection):
Query q = XPersistence.getManager().createQuery("JPQL QUERY TO RETRIVE THE COLLECTION WITH :parameterIfNeeded");
q.setParameter("parameterIfNeeded", "value");
List entityBList = q.getResultList();
if (getView().getModelName().equalsIgnoreCase("yourBaseModelViewName")) {
getView().getSubview("yourSubViewName").setModel(entityBList);
getView().getSubview("yourSubViewName").refresh();
}
You must to be using OX 4.6 to be able to use setModel(). And remember that the "yourSubViewName" is the name of the property for your collection into the base model.
I have not tested that code with a collection, so make the adjustments according to your needs, maybe you will need to CAST the query result list or something.
I am trying to create a grid using GXT that contains data from multiple JSON sources. I've been able to get the grid working with one source, but can't figure out how to add additional sources to the grid or the ListStore.
// ...
ScriptTagProxy<PagingLoadResult<ModelData>> proxy =
new ScriptTagProxy<PagingLoadResult<ModelData>>(url);
ModelType type = new ModelType();
type.setRoot("root");
type.addField("source");
type.addField("description");
JsonPagingLoadResultReader<PagingLoadResult<ModelData>> reader =
new JsonPagingLoadResultReader<PagingLoadResult<ModelData>>(type);
final PagingLoader<PagingLoadResult<ModelData>> loader =
new BasePagingLoader<PagingLoadResult<ModelData>>(proxy, reader);
ListStore<ModelData> store = new ListStore<ModelData>(loader);
final Grid<ModelData> grid = new Grid<ModelData>(store, cm);
add(grid);
// ...
Is there a way to add additional loaders to a GXT ListStore? Ideas? Thanks in advance.
It looks like one method of populating a grid with multiple remote sources is to use borrow from the article http://code.google.com/webtoolkit/articles/using_gwt_for_json_mashups.html and create a 'mashup' class that populates a ListStore with the results as each response is returned.
I tried setting the defaultvalue property of the field to Guid.NewGuid() but every item created has the same guid so I guess the Guid.NewGuid() is being stored as the default rather than being run each time.
Is the only way to achieve this to add an event handler to the list for OnAdded?
I'm assuming you're using a Single Line of Text field for this. The standard default for such a field is always a constant, you can't assign a variable or function via the object model. All that would do is assign the static result of that particular call of the function.
While text fields can support a calculated default value, it uses the same functions that are in Calculated columns, which do not support random numbers.
Your best bet is to use an Event Handler, I would recommend ItemAdding over ItemAdded as well. You'd be assigning to properties.AfterProperties["fieldname"] instead of field.DefaultValue, of course.
If you are creating the field through code and setting the field.DefaultValue = Guid.NewGuid(), this will run the Guid.NewGuid() and store the returned Guid as the default
It is the equlivant of running the folowing code:
Guid newGuid = Guid.NewGuid();
string newGuidString = newGuid.ToString();
field.DefaultValue = newGuidString;
I dont know of any method you can use to set the field to generate a new Guid on item creation other than using an Event handler.
It should be posable to genrate a random number using the field.DefaultValue = "RANDBETWEEN(10,20)"; but i have not tested this