How to catch find button event & apply condition after record search? - sapb1

I have used a following code for navigation of records in sales order.
if (pVal.MenuUID == "1291") //Last Data Record
{
Application.SBO_Application.MessageBox("Last");
SAPbouiCOM.Conditions conditions = new SAPbouiCOM.Conditions();
SAPbouiCOM.Condition condition = null;
condition = conditions.Add();
condition.Alias = "U_pdocentry";
condition.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
int offset = oForm.DataSources.DBDataSources.Item(0).Offset;
string DocEntry = oForm.DataSources.DBDataSources.Item(0).GetValue("DocEntry", offset); Application.SBO_Application.MessageBox(DocEntry);
condition.CondVal = DocEntry; // Querying the DB Data source
oDBDataSource.Query(conditions);
oMatrix.LoadFromDataSource();
Application.SBO_Application.MessageBox("last record");
}
I want to apply this same condition when we search records by clicking on find button. I know the id for this menu is 1281 but when we click on button & then search records by cardcode or cardname and after that record get open. So, How can I apply the above(In code)conditon after record search?

Related

hiddenfield, comparing textbox value when page load to after update

I want to check my textbox's values based on the row .
so I have a small database table in a gridview and I want to check wether the values have changed in order to trigger a specific database update query ( as I dont want to update every column when I change just one.
protected void grdIdkun_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int index = grdExcUsePolicy.EditIndex;
GridViewRow row = grdExcUsePolicy.Rows[index];
string id = ((Label)row.FindControl("lblId")).Text;
String name = ((TextBox)row.FindControl("txtName")).Text;
String created = ((TextBox)row.FindControl("txtCreated")).Text;
}
//that method will have new values as its not in page_load. pls help

Unable to set date values in SAP B1 matrix combobox

I am trying to set values in a matrix combobox but I cannot be able to set the first value of date to that combobox. It shows blank and when I select a date, it does not fill the field anyway.
The values I get from the DB are as follows:
Here is my code below including binding the combobox field to a userdatasource:
_expDate = _form.DataSources.UserDataSources.Add("iV_15", SAPbouiCOM.BoDataType.dt_DATE, 100);
oIColumns = oIMatrix.Columns;
_colExpDate = oIColumns.Item("iV_15");
_colExpDate.DataBind.SetBound(true, "", "iV_15");
The below code runs when there is a lost focus change event to the item selection field:
#region Item Change Event Expiry dates
_cmbExpDate = (SAPbouiCOM.ComboBox)oIMatrix.Columns.Item("iV_15").Cells.Item(pVal.Row).Specific;
int count = _cmbExpDate.ValidValues.Count;
if (count > 0)
{
_expDate.ValueEx = "";
for (int j = 0; j <= count - 1; j++)
_cmbExpDate.ValidValues.Remove(0, SAPbouiCOM.BoSearchKey.psk_Index);
}
var expDates = (from oi in _db.OITMs
join ob in _db.OBTNs
on oi.ItemCode equals ob.ItemCode
where ob.ItemCode == _itemNo.ValueEx && oi.OnHand > 0
orderby ob.ExpDate
select new
{
ExpDate = ob.ExpDate
}).Distinct().ToList();
if (expDates.Count > 0)
{
foreach (var item in expDates)
_cmbExpDate.ValidValues.Add(item.ExpDate?.ToString(), item.ExpDate?.ToString());
_cmbExpDate.Select(0, SAPbouiCOM.BoSearchKey.psk_Index);
_expDate.ValueEx = _cmbExpDate.Value;
}
#endregion
What could be wrong. Is there a better way to achieve what I need in SAP B1?
as a test try a different data type for your:
_expDate = _form.DataSources.UserDataSources.Add("iV_15", SAPbouiCOM.BoDataType.dt_DATE, 100);
test it with: SAPbouiCOM.BoDataType.dt_LONG_TEXT
you can also try just selecting the value on the combo, instead of setting uds as well.

multiple search in domino documents

In the onclick event of a button , I would like to search for a notes document , with multiple conditions with ssjs.
I have a form with a few fields. Now I would like to find a notes document where field a="123" and field b="456" field c="789" and field d >"A123456" , and then I would like to read the contents of field e.
If it was the search in a view I would use something like :
var tmpArray = new Array("");
var cTerms = 0;
if(viewScope.fong != null & viewScope.fong != "") {
tmpArray[cTerms++] = "(FIELD Site = \"" + viewScope.fong + "\")"
}
if(#Text(viewScope.sDate) != null & #Text(viewScope.sDate) != "") {
tmpArray[cTerms++] = "(FIELD StartDate = \"" + #Text(viewScope.sDate) + "\")"
}
qstring = tmpArray.join(" AND ").trim();
viewScope.queryString = qstring;
return qstring
If I only had 1 condition I would have used #DbLookup (and still how select documents >"A123456"?)
What's the best way of dooing this in ssjs ?
UPDATE
tried with FTSearch , but it seems in the searchkey "FIELD d > A123456" , doesn't seem to work
OTHER UPDATE
var dc = db.FTSearch("FIELD a=123 and FIELD b =456 and FIELD d =A123456");
seems to work but
var dc = db.FTSearch("FIELD a=123 and FIELD b =456 and FIELD d >A123456"); doesn't. It gives error : Exception occurred calling method NotesDatabase.FTSearch(string) null
If you want to use comparison operators > and <, then you need to use the NotesDatabase.Search method instead of FTSearch. Search is slower and can't access data in non-summary (i.e., rich text) fields, but it has all the same capabilities that you can use in a view selection formula.

How to customize the update functionality in ColdFusion ORM?

I want to customize the update function of ORM. By default, ORM loads the object that needs to be updated, makes updates, and then saves the object. I want to update a record when a certain condition is satisfied.
For example :
I want to update payment mode from credit card to cash. Before updating records I want to check that I already have a cash payment mode. If one exists then I do not need to update a record otherwise update the record.
For the above checking I have used this SQL:
SELECT COUNT(*)
FROM hr_lookup_paymentmode
WHERE PaymentMode = 'cash'
AND modeid <> '10'
Equivalent HQL:
/**
* #hint Determines total number of results with same value of search for update purposes.
*/
remote numeric function searchUpdateCount(string q,numeric modeid ) output="false" {
var hqlString = "";
var whereClause = "";
var params = {};
hqlString = hqlString & "SELECT count(*) ";
hqlString = hqlString & "FROM hr_lookup_paymentmode";
if (len(arguments.q) gt 0)
{
whereClause = ListAppend(whereClause, " PaymentMode = '#arguments.q#'", "|");
whereClause = ListAppend(whereClause, "modeid <> '#arguments.modeid#'", "|");
whereClause = Replace(whereClause, "|", " AND ", "all");
}
if (len(whereClause) gt 0){
hqlString = hqlString & " WHERE " & whereClause;
}
return ormExecuteQuery(hqlString, false, params)[1];
}
Parameter q = 'cash' and modeid = 10. If count found is greater than 0 means record already exists, otherwise go for update.
Please help me apply this logic.
You can use ORM event handlers - either globally defined or defined in specific ORM objects. Here is some information on event handlers, but basically you would do the following in your ORM object:
function preUpdate( obj, data ){
{do stuff here }
}
In this example obj is the ORM entity you are trying to save and data is a structure containing the old data from the ORM entity. You would simply add your logic to the body of the function.

Cannot add an entity that already exists. (LINQ to SQL)

in my database there are 3 tables
CustomerType
CusID
EventType
EventTypeID
CustomerEventType
CusID
EventTypeID
alt text http://img706.imageshack.us/img706/8806/inserevent.jpg
Dim db = new CustomerEventDataContext
Dim newEvent = new EventType
newEvent.EventTypeID = txtEventID.text
db.EventType.InsertOnSubmit(newEvent)
db.SubmitChanges()
'To select the last ID of event'
Dim lastEventID = (from e in db.EventType Select e.EventTypeID Order By EventTypeID Descending).first()
Dim chkbx As CheckBoxList = CType(form1.FindControl("CheckBoxList1"), CheckBoxList)
Dim newCustomerEventType = New CustomerEventType
Dim i As Integer
For i = 0 To chkbx.Items.Count - 1 Step i + 1
If (chkbx.Items(i).Selected) Then
newCustomerEventType.INTEVENTTYPEID = lastEventID
newCustomerEventType.INTSTUDENTTYPEID = chkbxStudentType.Items(i).Value
db.CustomerEventType.InsertOnSubmit(newCustomerEventType)
db.SubmitChanges()
End If
Next
It works fine when I checked only 1 Single ID of CustomerEventType from CheckBoxList1. It inserts data into EventType with ID 1 and CustomerEventType ID 1. However, when I checked both of them, the error message said
Cannot add an entity that already exists.
Any suggestions please? Thx in advance.
Did you change the EventID before you pressed the button again. To me it looks as you did not. This would result that the code tries to insert the event with the ID 1 into the database, although, it is already there.
Maybe try increasing the event ID automatically or check whether the event is alreay present before trying to insert it.
Edit:
OK, here is what I think you want to do ... if I understood it correctly (it's in C# as I am more fluent in that language - however you should be able to easily convert the algorithm to VB - so just take it as pseudo code):
var db = new CustomerEventDataContext();
var newEvent = db.EventTypeSingleOrDefault(x => x.EventTypeId == txtEventID.Text);
if (newEvent != null) {
newEvent = new EventType();
newEvent.EventTypeId = txtEventID.Text;
db.EventType.InsertOnSubmit();
}
var chkbx = (CheckBoxList) form1.FindControl("CheckBoxList1");
for (int i = 0; i < chkbx.Items.Count; i++) {
var value = chkbxStudentType.Items(i).Value;
if (db.CustomerEventTypes.SingleOrDefault(x => x.EventTypeId == newEvent.EventTypeId) != null) {
// item already exists
} else {
var newCustomerEventType = new CustomerEventType();
newCustomerEventType.INTEVENTTYPEID = newEvent.EventTypeId;
newCustomerEventType.INTSTUDENTTYPEID = value;
db.CustomerEventType.InsertOnSubmit(newCustomerEventType);
}
}
db.SubmitChanges();
Two things I noticed:
You were adding the new EventType and then selecting the last event type based upon the id. This may not result in the item you just added.
You do not have to call SubmitChanges after each InsertOnSubmit. The DataBaseContext implementaton holds the inserted objects for you and you can reference them. Then you do a single submit to commit all changes. Note, however, in some complex circumstances a separate SubmitChanges is necessary, but this is rarely the case.