I have 2 screen, inquiry and data entry.
and i want to copy Record from Screen1 to screen2, see picture below.
scree1 and Screen2
I use the following code:
public PXAction<FuncLocFilter> CreateFuncLoc;
[PXButton]
[PXUIField(DisplayName = "Create Functional Location")]
protected virtual void createFuncLoc()
{
FuncLocFilter row = Filter.Current;
BSMTFuncLoc FnLc = new BSMTFuncLoc();
FunLocEntry graph = PXGraph.CreateInstance<FunLocEntry>();
graph.FunLocations.Current.FuncLocCD = row.FuncLocCD;
graph.FunLocations.Current.StructureID = row.StructureID;
graph.FunLocations.Current.HierLevels = row.HierLevels;
graph.FunLocations.Current.EditMask = row.EditMask;
if (graph.FunLocations.Current != null)
{
throw new PXRedirectRequiredException(graph, true, "Functional Location");
}
}
but i encountered an error like the following:
Error
can someone please help solve this seemingly stupid question?
im sorry my english is bad.. :)
Thanks!
Below is a common pattern to create data records via code/programming in Acumatica
public PXAction<FuncLocFilter> CreateFuncLoc;
[PXButton]
[PXUIField(DisplayName = "Create Functional Location")]
protected virtual void createFuncLoc()
{
FuncLocFilter row = Filter.Current;
// 1. Create an instance of the BLC (graph)
FunLocEntry graph = PXGraph.CreateInstance<FunLocEntry>();
// 2. Create an instance of the BSMTFuncLoc DAC, set key field values (besides the ones whose values are generated by the system),
// and insert the record into the cache
BSMTFuncLoc FnLc = new BSMTFuncLoc();
FnLc.FuncLocCD = row.FuncLocCD;
FnLc = graph.FunLocations.Insert(FnLc);
// 3. Set non-key field values and update the record in the cache
FnLc.StructureID = row.StructureID;
FnLc.HierLevels = row.HierLevels;
FnLc.EditMask = row.EditMask;
FnLc = graph.FunLocations.Update(FnLc);
// 4. Redirect
if (graph.FunLocations.Current != null)
{
throw new PXRedirectRequiredException(graph, true, "Functional Location");
}
Related
I have a field in CROpportunity named UsrOrderTotalValue.
Sales Order(SO301000) and Opportunitis(CR304000) are linked with added to SOOrder tab custome field UsrOpportunityID.
When Save Button pusshed on Sales Order, it's needed to save to a UsrOrderTotalValue some Value.
Some code snipet is given below.
Besides below I tried different approaches of using Persist, but nothing works.
My Acumatica version:
Acumatica 2018 R1 (18.110.0017)
OpportunityMaint opportunityGraph = PXGraph.CreateInstance<OpportunityMaint>();
SOOrderExt sOOrderExt = row.GetExtension<SOOrderExt>();
CROpportunity cROpportunity = Opportunity.Select(sOOrderExt.UsrOpportunityID);
opportunityGraph.Opportunity.Update(cROpportunity);
opportunityGraph.Save.Press();
Try like below, I have hardcoded value, please replace with your fields.
[PXOverride]
public void Persist(Action del)
{
if ((Base.Document.Cache.GetStatus(Base.Document.Current) == PXEntryStatus.Inserted || Base.Document.Cache.GetStatus(Base.Document.Current) == PXEntryStatus.Updated))
{
OpportunityMaint opportunityGraph = PXGraph.CreateInstance<OpportunityMaint>();
CROpportunity cROpportunity = new CROpportunity();
cROpportunity.OpportunityID = "000001";
cROpportunity = opportunityGraph.Opportunity.Current = opportunityGraph.Opportunity.Select(cROpportunity);
if (cROpportunity != null)
cROpportunity.OpportunityName = "test";
opportunityGraph.Opportunity.Update(cROpportunity);
opportunityGraph.Save.Press();
}
del();
}
I’m fairly new to Project Server development and was wondering what modifications need to be made the following code I have to have it update multiple Custom Fields in one pass. I have everything working up until the point I want to start updating multiple Custom Fields. I’ve gone through numerous tutorials and haven’t found a solution that works for this issue. The current program I’ve put together only results in updating the first ForEach cfValueWOD Custom Field. I can get the code to update multiple fields if they already have a value but for my project these custom fields can either have an initial value or no value to start. In both cases I will need to write values to these fields. I need to complete this for a project at work very soon and I’m at a loss. Your help will be much appreciated. My current code is as follows:
{
static void WriteCustomFields()
{
//Guids for custom fields to update - Test
string cfNameWOD = "WO Description"; //Test WO Description custom field
string cfValueWOD = "xxxx5WODes";
Guid cfIdWOD = new Guid("{8071365c-1375-46a1-9424-cd79f3c2b0db}");
string cfNameWG = "Work Group"; //Test Work Group custom field
string cfValueWG = "xxxx5Group";
Guid cfIdWG = new Guid("{f75c6cfb-b7cb-4d35-8b04-60efb12fcd39}");
//projects into a dataset
ProjectDataSet projectList = projectSvc.ReadProjectList();
//read project data
Guid myProjectUid = new Guid("{c96bd7ea-e9d2-47ed-8819-02e4653e92a7}");
ProjectDataSet myProject = projectSvc.ReadProject(myProjectUid, DataStoreEnum.WorkingStore);
//indicate the custom field has been found
bool customFieldFound = false;
//iterate over fields and update them to the table for WO Status
foreach (ProjectDataSet.ProjectCustomFieldsRow cfRow in myProject.ProjectCustomFields)
{
//if field exists update it
if (cfRow.MD_PROP_UID == cfIdWOD)
{
//update the value
cfRow.TEXT_VALUE = cfValueWOD;
customFieldFound = true;
}
}
//check if the custom field has been found
if (!customFieldFound)
{
//create a new row
ProjectDataSet.ProjectCustomFieldsRow cfRowWOD =
myProject.ProjectCustomFields.NewProjectCustomFieldsRow();
//Sets all values to NUll to begin
cfRowWOD.SetDATE_VALUENull();
cfRowWOD.SetTEXT_VALUENull();
//General parameters
cfRowWOD.MD_PROP_UID = cfIdWOD; //custom field ID
cfRowWOD.CUSTOM_FIELD_UID = Guid.NewGuid();
cfRowWOD.PROJ_UID = myProjectUid; //current project ID
//add value
cfRowWOD.FIELD_TYPE_ENUM = 21;
cfRowWOD.TEXT_VALUE = Convert.ToString(cfValueWOD); //test value
//add the row to the data set
myProject.ProjectCustomFields.AddProjectCustomFieldsRow(cfRowWOD);
}
//iterate over fields and update them to the table for WO Status
foreach (ProjectDataSet.ProjectCustomFieldsRow cfRow in myProject.ProjectCustomFields)
{
//if field exists update it
if (cfRow.MD_PROP_UID == cfIdWG)
{
//update the value
cfRow.TEXT_VALUE = cfValueWG;
customFieldFound = true;
}
}
//check if the custom field has been found
if (!customFieldFound)
{
//create a new row
ProjectDataSet.ProjectCustomFieldsRow cfRowWG =
myProject.ProjectCustomFields.NewProjectCustomFieldsRow();
//Sets all values to NUll to begin
cfRowWG.SetDATE_VALUENull();
cfRowWG.SetTEXT_VALUENull();
//General parameters
cfRowWG.MD_PROP_UID = cfIdWG; //custom field ID
cfRowWG.CUSTOM_FIELD_UID = Guid.NewGuid();
cfRowWG.PROJ_UID = myProjectUid; //current project ID
//add value
cfRowWG.FIELD_TYPE_ENUM = 21;
cfRowWG.TEXT_VALUE = Convert.ToString(cfValueWG); //test value
//add the row to the data set
myProject.ProjectCustomFields.AddProjectCustomFieldsRow(cfRowWG);
}
//generate sessionId for tracking
Guid sessionId = Guid.NewGuid(); //sessionId for updating process
Guid jobId = Guid.NewGuid(); //ID for each job
//check out project
projectSvc.CheckOutProject(myProjectUid, sessionId,
"update checkout");
//update project database
bool validateOnly = false;
projectSvc.QueueUpdateProject(jobId, sessionId,
myProject, validateOnly);
//wait to finish
WaitForJob(jobId);
//new jobId to check in the project
jobId = Guid.NewGuid();
//check in the updated project
bool force = false;
string sessionDescription = "update custom fields";
projectSvc.QueueCheckInProject(jobId, myProjectUid,
force, sessionId, sessionDescription);
//wait to finish
WaitForJob(jobId);
//new jobId to publish the project
jobId = Guid.NewGuid();
bool fullPublish = true;
projectSvc.QueuePublish(jobId, myProjectUid, fullPublish, null);
//wait to finish
WaitForJob(jobId);
}
As per my understanding, you are updating a project custom field. Updating a custom field is nothing but up updating a project. In order to do that, first you have to check out a project,Update the custom field, and then call the Queue publish method to save and publish it.
But in your code, You are checking out only one project. So you can update the custom fields that belongs to only that project.
Inorder to update multiple custom fields then your code should be more dynamic.
Example :
read project Guid dynamically.
Loop in thru the project Guid's, then
{
Get Custom field Dataset.
Read custom field dataset.
compare custom fields guids, pick the custom field values based on Project Guid and Custom Field Guid.
Set the value and finally update it.
}
Currently, I'm sending some data to Parse.com. All works well, however, I would like to add a row if it's a new user or update the current table if it's an old user.
So what I need to do is check if the current Facebook ID (the key I'm using) shows up anywhere in the fbid column, then update it if case may be.
How can I check if the key exists in the column?
Also, I'm using C#/Unity.
static void sendToParse()
{
ParseObject currentUser = new ParseObject("Game");
currentUser["name"] = fbname;
currentUser["email"] = fbemail;
currentUser["fbid"] = FB.UserId;
Task saveTask = currentUser.SaveAsync();
Debug.LogError("Sent to Parse");
}
Okay, I figured it out.
First, I check which if there is any Facebook ID in the table that matches the current ID, then get the number of matches.
public static void getObjectID()
{
var query = ParseObject.GetQuery("IdealStunts")
.WhereEqualTo("fbid", FB.UserId);
query.FirstAsync().ContinueWith(t =>
{
ParseObject obj = t.Result;
objectID = obj.ObjectId;
Debug.LogError(objectID);
});
}
If there is any key matching the current Facebook ID, don't do anything. If there aren't, just add a new user.
public static void sendToParse()
{
if (count != 0)
{
Debug.LogError("Already exists");
}
else
{
ParseObject currentUser = new ParseObject("IdealStunts");
currentUser["name"] = fbname;
currentUser["email"] = fbemail;
currentUser["fbid"] = FB.UserId;
Task saveTask = currentUser.SaveAsync();
Debug.LogError("New User");
}
}
You will have to do a StartCoroutine for sendToParse, so getObjectID has time to look through the table.
It may be a crappy implementation, but it works.
What you need to do is create a query for the fbid. If the query returns an object, you update it. If not, you create a new.
I'm not proficient with C#, but here is an example in Objective-C:
PFQuery *query = [PFQuery queryWithClassName:#"Yourclass]; // Name of your class in Parse
query.cachePolicy = kPFCachePolicyNetworkOnly;
[query whereKey:#"fbid" equalTo:theFBid]; // Variable containing the fb id
NSArray *users = [query findObjects];
self.currentFacebookUser = [users lastObject]; // Array should contain only 1 object
if (self.currentFacebookUser) { // Might have to test for NULL, but probably not
// Update the object and save it
} else {
// Create a new object
}
We are having an issue with searching a custom record through SuiteTalk. Below is a sample of what we are calling. The issue we are having is in trying to set up the search using the internalId of the record. The issue here lies in in our initial development account the internal id of this custom record is 482 but when we deployed it through the our bundle the record was assigned with the internal Id of 314. It would stand to reason that this internal id is not static in a site per site install so we wondered what property to set up to reference the custom record. When we made the record we assigned its “scriptId’ to be 'customrecord_myCustomRecord' but through suitetalk we do not have a “scriptId”. What is the best way for us to allow for this code to work in all environments and not a specific one? And if so, could you give an example of how it might be used.
Code (C#) that we are attempting to make the call from. We are using the 2013.2 endpoints at this time.
private SearchResult NetSuite_getPackageContentsCustomRecord(string sParentRef)
{
List<object> PackageSearchResults = new List<object>();
CustomRecord custRec = new CustomRecord();
CustomRecordSearch customRecordSearch = new CustomRecordSearch();
SearchMultiSelectCustomField searchFilter1 = new SearchMultiSelectCustomField();
searchFilter1.internalId = "customrecord_myCustomRecord_sublist";
searchFilter1.#operator = SearchMultiSelectFieldOperator.anyOf;
searchFilter1.operatorSpecified = true;
ListOrRecordRef lRecordRef = new ListOrRecordRef();
lRecordRef.internalId = sParentRef;
searchFilter1.searchValue = new ListOrRecordRef[] { lRecordRef };
CustomRecordSearchBasic customRecordBasic = new CustomRecordSearchBasic();
customRecordBasic.recType = new RecordRef();
customRecordBasic.recType.internalId = "314"; // "482"; //THIS LINE IS GIVING US THE TROUBLE
//customRecordBasic.recType.name = "customrecord_myCustomRecord";
customRecordBasic.customFieldList = new SearchCustomField[] { searchFilter1 };
customRecordSearch.basic = customRecordBasic;
// Search for the customer entity
SearchResult results = _service.search(customRecordSearch);
return results;
}
I searched all over for a solution to avoid hardcoding internalId's. Even NetSuite support failed to give me a solution. Finally I stumbled upon a solution in NetSuite's knowledgebase, getCustomizationId.
This returns the internalId, scriptId and name for all customRecord's (or customRecordType's in NetSuite terms! Which is what made it hard to find.)
public string GetCustomizationId(string scriptId)
{
// Perform getCustomizationId on custom record type
CustomizationType ct = new CustomizationType();
ct.getCustomizationTypeSpecified = true;
ct.getCustomizationType = GetCustomizationType.customRecordType;
// Retrieve active custom record type IDs. The includeInactives param is set to false.
GetCustomizationIdResult getCustIdResult = _service.getCustomizationId(ct, false);
foreach (var customizationRef in getCustIdResult.customizationRefList)
{
if (customizationRef.scriptId == scriptId) return customizationRef.internalId;
}
return null;
}
you can make the internalid as an external property so that you can change it according to environment.
The internalId will be changed only when you install first time into an environment. when you deploy it into that environment, the internalid will not change with the future deployments unless you choose Add/Rename option during deployment.
I have a project that inserts personal information to a table and details into another table. But sometimes personal information cannot be recorded, however details are recorded. As below code part, firstly personal information are inserted, then details. But sometimes personal information doesn't get saved and userId returns 0, So details are saved. I don't know why it doesn't work. Any idea?
public int ConferenceIdyeGoreKisiBilgileriniKaydet(string orderId)
{
KisiselBilgilerBal kisiBilgileri = (KisiselBilgilerBal)Session["kisiselBilgilerSession"];
registrationCode = GenerateGeristrationCode();
string toplamMaliyet = Session["toplamOdeme"].ToString();
PersonalInformation.SavePersonalInformations(kisiBilgileri, registrationCode,conferenceName);
int userId = AuthorPaperDetaylari.AdVeSoyadaGoreIdGetir(kisiBilgileri.f_name, kisiBilgileri.l_name);
AuthorPaperDetaylari.SaveAuthorPaperDetails(authorPaperDetay, userId); // save details via userId.
return userId;
}
This method saves personal information.
public static void SavePersonalInformations(KisiselBilgilerBal kisiBilgileri,string registrationCode,string conferenceName)
{
try
{
string cs = ConfigurationManager.AppSettings["SiteSqlServer"];
DBDataContext db = new DBDataContext(cs);
DBpersonalInformation personalInfo = new DBpersonalInformation();
personalInfo.f_name = kisiBilgileri.f_name;
personalInfo.l_name = kisiBilgileri.l_name;
personalInfo.university_affiliation = kisiBilgileri.university_affiliation;
personalInfo.department_name = kisiBilgileri.department_name;
personalInfo.address1 = kisiBilgileri.address1;
personalInfo.address2 = kisiBilgileri.address2;
personalInfo.city = kisiBilgileri.city;
personalInfo.state = kisiBilgileri.state;
personalInfo.zipCode = kisiBilgileri.zipCode;
personalInfo.country = kisiBilgileri.country;
personalInfo.phone = kisiBilgileri.phone;
personalInfo.email = kisiBilgileri.email;
personalInfo.orderId = kisiBilgileri.orderId;
personalInfo.registrationCode = registrationCode;
personalInfo.date = DateTime.Now;
personalInfo.conferenceName = conferenceName;
db.DBpersonalInformations.InsertOnSubmit(personalInfo);
db.SubmitChanges();
}
catch (Exception)
{
}
}
This method saves details
public static void SaveAuthorPaperDetails(AuthorPaperDetailsBal authorPaperDetay, int userId)
{
try
{
string cs = ConfigurationManager.AppSettings["SiteSqlServer"];
DBWebDataContext db = new DBWebDataContext(cs);
DBAuthorPaperDetail authorPaperDetail = new DBAuthorPaperDetail();
authorPaperDetail.paper_title = authorPaperDetay.paperTitleDetails;
authorPaperDetail.conference_maker_id = authorPaperDetay.confMakerId;
authorPaperDetail.additional_paper_title = authorPaperDetay.additionalPprTtle;
authorPaperDetail.areYouMainAuthor = authorPaperDetay.mainAuthor;
authorPaperDetail.feeForFirstAuthorPaper = authorPaperDetay.registerFeeForFirstAuthor;
authorPaperDetail.feeForAdditionalPaper = authorPaperDetay.regFeeForAdditionalPape;
authorPaperDetail.feeForParticipCoAuthors = authorPaperDetay.regFeeForCoAuthors;
authorPaperDetail.userId = userId;
authorPaperDetail.firstCoAuthorName = authorPaperDetay.firstCoAuthor;
authorPaperDetail.secondCoAuthorName = authorPaperDetay.secondCoAutho;
authorPaperDetail.thirdCoAuthorName = authorPaperDetay.thirdCoAuthor;
authorPaperDetail.toplamOdeme = authorPaperDetay.toplamMaliyet;
db.DBAuthorPaperDetails.InsertOnSubmit(authorPaperDetail);
db.SubmitChanges();
}
catch (Exception)
{
}
}
I don't know why it doesnt work. Any idea?
...
catch (Exception)
{
}
Well, that explains pretty much everything... don't do this. Ever. The database layer is trying to tell you what the problem is, and you are sticking your fingers in your ears, hoping that'll make it go away. If I had to guess: maybe an occasional timeout due to being blocked by another SPID.
If you can't do anything useful or appropriate with an exception, just let it bubble to the caller. If it gets to the UI, tell the user about it (or just log the issue internally and tell the user "There was a problem").
Also, a LINQ-to-SQL data-context is IDisposable; you should have using statement around db.
In addition to Marc's answer... You are calling SubmitChanges twice. If you want atomic data storage, you should call it once. You can use relational properties to create an object graph, and submit the whole graph at once.
public void SaveParentAndChildren()
{
using (CustomDataContext myDC = new CustomDataContext())
{
Parent p = new Parent();
Child c = new Child();
p.Children.Add(c);
myDC.Parents.InsertOnSubmit(p); //whole graph is now tracked by this data context
myDC.SubmitChanges(); // whole graph is now saved to database
// or nothing saved if an exception occurred.
} //myDC.Dispose is called for you here whether exception occurred or not
}