How can I insert a note into a sales order notes while inserting a sales order using the api? - erp

I am using Acumatica 4.2 and inserting Sales Orders through the api from another system.
The request has come up to add notes to the sales order and I am not seeing anything useful on how to go about doing this. thanks in advance. Here is my code for inserting the SalesOrder using the Acumatica WebAPI. It functions very well.
On the Sales Order Screen there is also a Notes indicator on the upper right where notes can be added to the sales order. How would I go about adding a note by using the acumatica web api? or do I simply use the returned SONumber and insert the note using the SONumber as a reference. I have not had to deal with notes before.
try
{
cmds.AddRange(
new SO301000_509.Command[]
{
so301000.Actions.Insert,
new SO301000_509.Value { Value = "SO", LinkedCommand = so301000.OrderSummary.OrderType },
new SO301000_509.Value { Value = "='new'", LinkedCommand = so301000.OrderSummary.OrderNbr },
new SO301000_509.Value { Value = dealerOrder.accountCode, LinkedCommand = so301000.OrderSummary.Customer },
//new SO301000_509.Value { Value = ((DateTime)dealerOrder.orderDateTime).ToShortDateString(), LinkedCommand = so301000.OrderSummary.Date },
new SO301000_509.Value { Value = (dealerOrder.orderDateTime), LinkedCommand = so301000.OrderSummary.Date },
new SO301000_509.Value { Value = "Hubsoft Order Nbr: " + dealerOrder.hubsoftOrderNumber, LinkedCommand = so301000.OrderSummary.Description },
new SO301000_509.Value { Value = dealerOrder.hubsoftOrderNumber, LinkedCommand = so301000.OrderSummary.CustomerRef },
new SO301000_509.Value { Value = "HS-" + dealerOrder.purchaseOrderNumber, LinkedCommand = so301000.OrderSummary.CustomerOrder },
//new SO301000_509.Value { Value = dealerOrder.hubsoftOrderNumber, LinkedCommand = so301000.OrderSummary.ControlTotal },
}
);
//create the sales order lines in loop
for (var idx = 0; idx < SalesOrderLine.Length; idx++)
{
cmds.AddRange(
new SO301000_509.Command[]
{
so301000.DocumentDetails.ServiceCommands.NewRow,
//simple line adding
so301000.DocumentDetails.ServiceCommands.NewRow,
new SO301000_509.Value { Value = SalesOrderLine[idx].inventoryCD, LinkedCommand = so301000.DocumentDetails.InventoryID },
new SO301000_509.Value { Value = SalesOrderLine[idx].UOM, LinkedCommand = so301000.DocumentDetails.UOM },
new SO301000_509.Value { Value = SalesOrderLine[idx].Qty, LinkedCommand = so301000.DocumentDetails.Quantity },
new SO301000_509.Value { Value = "MAIN", LinkedCommand = so301000.DocumentDetails.Warehouse},
new SO301000_509.Value { Value = SalesOrderLine[idx].UnitPrice, LinkedCommand = so301000.DocumentDetails.UnitPrice, Commit = true },
}
);
}
cmds.Add(so301000.Actions.Save); //save all
cmds.Add(so301000.OrderSummary.OrderNbr); //return Order #
SO301000_509.Content[] SO301000Content = context.Submit(cmds.ToArray()); //submit
PXTrace.WriteInformation(SO301000Content[0].OrderSummary.OrderNbr.Value);
acumaticaSONbr = SO301000Content[0].OrderSummary.OrderNbr.Value;
}
catch (Exception ex)
{
PXTrace.WriteError("Error adding Sales Order - " + ex.Message);
}
return acumaticaSONbr;

Content SO301000 = context.GetSchema();
context.Clear();
Content[] result = context.Submit(
new Command[]{
new Value { Value = "000586", LinkedCommand = SO301000.OrderSummary.OrderNbr, Commit = true },
new Value { Value = "NoteText", LinkedCommand = SO301000.OrderSummary.NoteText, Commit = true },
SO301000.Actions.Save
}
);

Another way of doing this is within the first insert of the Sales Order itself.
The example posted by acumember required a 2nd call to the API.
Since we are inserting many Sales Orders at a time, we want to limit our calls.
So the following also works and requires only the one call.
thanks
try
{
cmds.AddRange(
new SO301000_509.Command[]
{
so301000.Actions.Insert,
new SO301000_509.Value { Value = "SO", LinkedCommand = so301000.OrderSummary.OrderType },
new SO301000_509.Value { Value = "='new'", LinkedCommand = so301000.OrderSummary.OrderNbr },
new SO301000_509.Value { Value = dealerOrder.accountCode, LinkedCommand = so301000.OrderSummary.Customer },
new SO301000_509.Value { Value = (dealerOrder.orderDateTime), LinkedCommand = so301000.OrderSummary.Date },
new SO301000_509.Value { Value = "Hubsoft Order Nbr: " + dealerOrder.hubsoftOrderNumber, LinkedCommand = so301000.OrderSummary.Description },
new SO301000_509.Value { Value = dealerOrder.hubsoftOrderNumber, LinkedCommand = so301000.OrderSummary.CustomerRef },
new SO301000_509.Value { Value = "HS-" + dealerOrder.purchaseOrderNumber, LinkedCommand = so301000.OrderSummary.CustomerOrder },
**new SO301000_509.Value { Value = dealerOrder.notes, LinkedCommand = so301000.OrderSummary.NoteText},**
new SO301000_509.Value { Value = "1", LinkedCommand = so301000.ShippingSettingsShipToInfo.OverrideAddress },
new SO301000_509.Value { Value = shipStreet1, LinkedCommand = so301000.ShippingSettingsShipToInfo.AddressLine1 },
new SO301000_509.Value { Value = shipStreet2, LinkedCommand = so301000.ShippingSettingsShipToInfo.AddressLine2 },
new SO301000_509.Value { Value = shipCity, LinkedCommand = so301000.ShippingSettingsShipToInfo.City },
new SO301000_509.Value { Value = shipState, LinkedCommand = so301000.ShippingSettingsShipToInfo.State },
new SO301000_509.Value { Value = shipCountry, LinkedCommand = so301000.ShippingSettingsShipToInfo.Country },
new SO301000_509.Value { Value = shipPostal, LinkedCommand = so301000.ShippingSettingsShipToInfo.PostalCode },
}
);
//create the sales order lines in loop
for (var idx = 0; idx < SalesOrderLine.Length; idx++)
{
cmds.AddRange(
new SO301000_509.Command[]
{
so301000.DocumentDetails.ServiceCommands.NewRow,
//simple line adding
so301000.DocumentDetails.ServiceCommands.NewRow,
new SO301000_509.Value { Value = SalesOrderLine[idx].inventoryCD, LinkedCommand = so301000.DocumentDetails.InventoryID },
new SO301000_509.Value { Value = SalesOrderLine[idx].UOM, LinkedCommand = so301000.DocumentDetails.UOM },
new SO301000_509.Value { Value = SalesOrderLine[idx].Qty, LinkedCommand = so301000.DocumentDetails.Quantity },
new SO301000_509.Value { Value = "MAIN", LinkedCommand = so301000.DocumentDetails.Warehouse},
new SO301000_509.Value { Value = SalesOrderLine[idx].UnitPrice, LinkedCommand = so301000.DocumentDetails.UnitPrice, Commit = true },
}
);
}
cmds.Add(so301000.Actions.Save); //save all
cmds.Add(so301000.OrderSummary.OrderNbr); //return Order #

Related

How to instantly access the saved row

I was wrote some code in Asp MVC with EF technology, I have condition line to find row with today date if i was not found i add it to database and then use the saved row for another process, but i get error when i refresh error page it work fine ! i think my code can not work async!
any body can help me to found my wrong ?
public ActionResult LineRegimeSave(string breakFast, string snake1, string lunch, string snake2, string snake3,string dinner, string snake4,string adviseText, string docFooterId)
{
ApplicationDbContext myContext = new ApplicationDbContext();
var docFooter = docFooterId != "null" ? myContext.DocFooters.Single(d => d.Id.ToString() == docFooterId) : null;
var strLine="BreakFast,"+ breakFast + "/Snake1,"+ snake1 + "/Lunch,"+ lunch + "/Snake2,"+ snake2 + "/Snake3,"+ snake3 + "/Dinner,"+ dinner + "/Snake4,"+snake4;
TriageRecord getMedicalRecId;
var userId = Session["NID"];
var userProfile = myContext.UserProfiles.Single(b => b.NationalId.ToString() == userId.ToString());
getMedicalRecId = myContext.TriageRecords.Where(u => u.UserProfile.Id == userProfile.Id)
.OrderByDescending(d => d.DateTime).First();
if (getMedicalRecId.DateTime.Date != DateTime.Today)
{
TriageRecord insert = new TriageRecord
{
Bust = getMedicalRecId.Bust,
Diastolic = getMedicalRecId.Diastolic,
HeartRate = getMedicalRecId.HeartRate,
Systolic = getMedicalRecId.Systolic,
Height = getMedicalRecId.Height,
Weight = getMedicalRecId.Weight,
Wrist = getMedicalRecId.Wrist,
Waist = getMedicalRecId.Waist,
Hips = getMedicalRecId.Hips,
UserProfile = getMedicalRecId.UserProfile,
DateTime = DateTime.Now
};
insert.MedicalRecord = new MedicalRecord
{
TriageRecord = insert,
VisitDate = DateTime.Now,
};
myContext.TriageRecords.Add(insert);
myContext.SaveChanges();
getMedicalRecId = myContext.TriageRecords.Where(u => u.UserProfile.Id == userProfile.Id)
.OrderByDescending(d => d.DateTime).First();
getMedicalRecId.MedicalRecord.MedicalRecordDetails.Add
(
new MedicalRecordDetail
{
DateTime = DateTime.Now,
VisitMode = "LineDiet",
VisitSummary = strLine,
DocFooter = docFooter,
AdviseText = adviseText
}
);
myContext.SaveChanges();
}
else
{
getMedicalRecId.MedicalRecord.MedicalRecordDetails.Add
(
new MedicalRecordDetail
{
DateTime = DateTime.Now,
VisitMode = "LineDiet",
VisitSummary = strLine,
DocFooter = docFooter,
AdviseText = adviseText
}
);
myContext.SaveChanges();
}
return RedirectToAction("LineRegimePrint",new { id = getMedicalRecId.Id});
}
Error occur on this line :
getMedicalRecId.MedicalRecord.MedicalRecordDetails.Add
(
new MedicalRecordDetail
{
DateTime = DateTime.Now,
VisitMode = "LineDiet",
VisitSummary = strLine,
DocFooter = docFooter,
AdviseText = adviseText
}
);
Error text is : Null reference...
Thank you.
update :
insert.MedicalRecord = new MedicalRecord
{
TriageRecord = insert,
VisitDate = DateTime.Now,
};
myContext.TriageRecords.Add(insert);
myContext.SaveChanges();
Do i need to change this code ?
var a = insert.MedicalRecord = new MedicalRecord
{
TriageRecord = insert,
VisitDate = DateTime.Now,
};
myContext.TriageRecords.Add(insert);
myContext.MedicalRecords.Add(a);
So according to you the problem occurs whenever you try to add an item to the list, but it says the object is null, so you need to check for that.
public ActionResult LineRegimeSave(string breakFast, string snake1, string lunch, string snake2, string snake3,string dinner, string snake4,string adviseText, string docFooterId)
{
...
getMedicalRecId = myContext.TriageRecords.Where(u => u.UserProfile.Id == userProfile.Id).OrderByDescending(d => d.DateTime).First();
if(getMedicalRecId != null) {
if (getMedicalRecId.DateTime.Date != DateTime.Today)
{
...
insert.MedicalRecord = new MedicalRecord
{
TriageRecord = insert,
VisitDate = DateTime.Now,
MedicalRecordDetails = new List<MedicalRecordDetail>(){ new MedicalRecordDetail
{
DateTime = DateTime.Now,
VisitMode = "LineDiet",
VisitSummary = strLine,
DocFooter = docFooter,
AdviseText = adviseText
}
};
myContext.SaveChanges();
}
}
else
{
....
}
else
{
throw new Exception("The current user profile has no triage records!");
}
return RedirectToAction("LineRegimePrint",new { id = getMedicalRecId.Id});
}

jsTree not getting data from server

In my mvc application, I have used jsTree,
my view
#{
ViewBag.Title = "OnDemand";
}
<script src="~/Scripts/jquery-1.9.1.min.js"></script>
<script src="~/Scripts/jstree.min.js"></script>
<h2>OnDemand - Treeview</h2>
<div id="demo1">
</div>
<script type="text/javascript">
jQuery(function($) {
$("#demo1").jstree({
"json_data": {
"ajax": {
"type": "POST",
"dataType": "json",
"async": true,
"contentType": "application/json;",
"opts": {
"method": "POST",
"url": "/Treeview/GetAllNodes11"
},
"url": "/Treeview/GetAllNodes11",
"data": function (node) {
if (node == -1) {
return '{ "operation" : "get_children", "id" : -1 }';
}
else {
//get the children for this node
return '{ "operation" : "get_children", "id" : ' + $(node).attr("id") + ' }';
}
},
"success": function (retval) {
return retval.d;
},
}
},
"plugins": ["themes", "json_data"]
});
});
</script>
my controller
[HttpPost]
public JsonResult GetAllNodes11(string id)
{
List G_JSTreeArray = new List();
G_JSTree _G_JSTree = new G_JSTree();
_G_JSTree.data = "x1";
_G_JSTree.state = "closed";
_G_JSTree.IdServerUse = 10;
_G_JSTree.children = null;
_G_JSTree.attr = new G_JsTreeAttribute { id = "10", selected = false };
G_JSTreeArray.Add(_G_JSTree);
G_JSTree _G_JSTree2 = new G_JSTree();
var children =
new G_JSTree[]
{
new G_JSTree { data = "x1-11", attr = new G_JsTreeAttribute { id = "201" } },
new G_JSTree { data = "x1-12", attr = new G_JsTreeAttribute { id = "202" } },
new G_JSTree { data = "x1-13", attr = new G_JsTreeAttribute { id = "203" } },
new G_JSTree { data = "x1-14", attr = new G_JsTreeAttribute { id = "204" } },
};
_G_JSTree2.data = "x2";
_G_JSTree2.IdServerUse = 20;
_G_JSTree2.state = "closed";
_G_JSTree2.children = children;
_G_JSTree2.attr = new G_JsTreeAttribute { id = "20", selected = true };
G_JSTreeArray.Add(_G_JSTree2);
G_JSTree _G_JSTree3 = new G_JSTree();
var children2 =
new G_JSTree[]
{
new G_JSTree { data = "x2-11", attr = new G_JsTreeAttribute { id = "301" } },
new G_JSTree { data = "x2-12", attr = new G_JsTreeAttribute { id = "302" }, children= new G_JSTree[]{new G_JSTree{data = "x2-21", attr = new G_JsTreeAttribute { id = "3011" }}} },
new G_JSTree { data = "x2-13", attr = new G_JsTreeAttribute { id = "303" } },
new G_JSTree { data = "x2-14", attr = new G_JsTreeAttribute { id = "304" } },
};
_G_JSTree3.data = "x3";
_G_JSTree3.state = "closed";
_G_JSTree3.IdServerUse = 30;
_G_JSTree3.children = children2;
_G_JSTree3.attr = new G_JsTreeAttribute { id = "30", selected = true };
G_JSTreeArray.Add(_G_JSTree3);
return new JsonResult { Data = G_JSTreeArray, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
but it does not hitting the controller
what is the issue with this code?
data cannot be a function so dynamic data assignment based on selected node is not evaluated but you use assign url with a function to change parameter to pass to controller. you must use GET method to retrieve data from controller -
Try this
"json_data": {
ajax: {
"url": function (node) {
var url;
if (node == -1) {
url = "/Treeview/GetAllNodes11/?operation=get_children";
} else {
var id = $(node).attr("id");
url = "/Treeview/GetAllNodes11/?operation=get_children&id=" + id;
}
return url;
},
"type": "GET",
"dataType": "json",
"contentType": "application/json charset=utf-8",
},
},

Accessing Existing db context property

I've tried to solve this fro quite some time already with no luck, guessing it will be a doddle for someone with experience. I'm using the MvcMusicStore.
I have a db context and I have added a new album with a new Genre. If I want to add another album with the same Genre, how do I assign the existing Genre to the new album? As in the second album below. Thanks in advance for any help.
protected override void Seed(Models.MusicStoreDBContext context)
{
context.Artists.Add(new Models.Artist { Name = "Al Di Meola" });
context.Genres.Add(new Models.Genre { Name = "Jazz" });
context.Albums.Add(new Models.Album
{
Artist = new Models.Artist { Name = "Sublime" },
Genre = new Models.Genre { Name = "Rock" },
Price = 11.99m,
Title = "40oz to Freedom"
});
context.Albums.Add(new Models.Album
{
Artist = new Models.Artist { Name = "Jawbox" },
Genre = "Rock", // HOW DO I ASSIGN THIS?
Price = 10.99m,
Title = "For your own special sweetheart"
});
just use a variable ?
var rock = new Models.Genre{Name="Rock"};
context.Genres.Add(rock);
context.Albums.Add(new Models.Album
{
Artist = new Models.Artist { Name = "Sublime" },
Genre = rock,
Price = 11.99m,
Title = "40oz to Freedom"
});
context.Albums.Add(new Models.Album
{
Artist = new Models.Artist { Name = "Jawbox" },
Genre = rock
Price = 10.99m,
Title = "For your own special sweetheart"
});
Just assign your new Genre to a variable and then set the property to that variable.
var rockGenre = new Models.Genre() { Name = "Rock" };
context.Genres.Add(rockGenre);
context.Albums.Add(new Models.Album
{
Artist = new Models.Artist { Name = "Sublime" },
Genre = rockGenre,
Price = 11.99m,
Title = "40oz to Freedom"
});
context.Albums.Add(new Models.Album
{
Artist = new Models.Artist { Name = "Jawbox" },
Genre = rockGenre,
Price = 10.99m,
Title = "For your own special sweetheart"
});
Or SubQuery?
protected override void Seed(Models.MusicStoreDBContext context)
{
context.Artists.Add(new Models.Artist { Name = "Al Di Meola" });
context.Genres.Add(new Models.Genre { Name = "Jazz" });
context.Albums.Add(new Models.Album
{
Artist = new Models.Artist { Name = "Sublime" },
Genre = new Models.Genre { Name = "Rock" },
Price = 11.99m,
Title = "40oz to Freedom"
});
context.Albums.Add(new Models.Album
{
Artist = new Models.Artist { Name = "Jawbox" },
Genre = (context.Genres.FirstOrDefault(x=>x.Name=="Rock")),
Price = 10.99m,
Title = "For your own special sweetheart"
});
}

Dev Express Mvc Editing GridViewSetting error?

my code is too long so sorry :)
#model IEnumerable<Osos11.Models.Customers>
#Html.DevExpress().GridView(
settings =>
{
settings.Name = "gvEditing";
settings.KeyFieldName = "sno";
settings.CallbackRouteValues = new { Controller = "Customer", Action = "EditingPartial" };
settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
settings.Columns.Add(column =>
{
column.Caption = "#";
column.SetDataItemTemplateContent(c =>
{
ViewContext.Writer.Write(
Html.ActionLink("Edit", "EditingEdit", new { sno = DataBinder.Eval(c.DataItem, "sno") }) + " " +
Html.ActionLink("Delete", "EditingDelete", new { sno = DataBinder.Eval(c.DataItem, "sno") },
new { onclick = "return confirm('Do you really want to delete this record?')" })
);
});
column.SetHeaderTemplateContent(c =>
{
ViewContext.Writer.Write(
Html.ActionLink("New", "EditingEdit", new { sno = -1 }).ToHtmlString()
);
});
column.Settings.AllowDragDrop = DefaultBoolean.False;
column.Settings.AllowSort = DefaultBoolean.False;
column.Width = 70;
});
settings.Columns.Add("Name");
//settings.Columns.Add(column =>
//{
// column.FieldName = "CategoryID";
// column.Caption = "Category";
// column.ColumnType = MVCxGridViewColumnType.ComboBox;
// var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
// comboBoxProperties.DataSource = NorthwindDataProvider.GetCategories();
// comboBoxProperties.TextField = "CategoryName";
// comboBoxProperties.ValueField = "CategoryID";
// comboBoxProperties.ValueType = typeof(int);
//});
settings.Columns.Add("CustomerNumber");
//settings.Columns.Add("UnitPrice").PropertiesEdit.DisplayFormatString = "c";
//settings.Columns.Add("UnitsInStock");
//settings.Columns.Add("Discontinued", MVCxGridViewColumnType.CheckBox);
settings.ClientLayout = (s, e) =>
{
if (e.LayoutMode == ClientLayoutMode.Loading)
{
if (Session["GridState"] != null)
e.LayoutData = (string)Session["GridState"];
}
else
Session["GridState"] = e.LayoutData;
};
settings.PreRender = (s, e) =>
{
if (ViewData["VisibleID"] == null) return;
ASPxGridView grid = (ASPxGridView)s;
grid.MakeRowVisible(ViewData["VisibleID"]);
};
}).Bind(Model).GetHtml()
I got this error
Compiler Error Message: CS1660: Cannot convert lambda expression to type 'DevExpress.Web.Mvc.GridViewSettings' because it is not a delegate type
It seems that this issue is caused by the fact that any expression in the GridView's definition is not valid.
As a result, the entire GridView's definition (lambda expression) cannot be recognized by the View Engine.

problem with Html.DropDownFor and selected item

I can't figure Html.DropDownFor out to work properly when SelectListItem Text is different from Value. This issue is when marking an specific item as selected="true" and everything is failed! (Nothing is marked as selected="true")
public IEnumerable<SelectListItem> HaveFail {
get {
return
IoC.Container.Resolve<Something>().GetAll().Select(
x =>
new SelectListItem {
Text = x.Key,
Value = x.Value.ToString(),
Selected = (string.Compare(x.Key, myValue) == 0)
});
}
}
public IEnumerable<SelectListItem> WorksFine {
get {
return
IoC.Container.Resolve<Something>().GetAll().Select(
x =>
new SelectListItem {
Text = x.Key,
Value = x.Key,
Selected = (string.Compare(x.Key, myValue) == 0)
});
}
}
You've got it backwards.
new SelectListItem
{
Text = x.Value.ToString(),
Value = x.Key,
Selected = (string.Compare(x.Key, myValue) == 0)
}

Resources