How to use Script to set a Netsuite System Field as Mandatory? - client

I have a Client Suitescript 2.0 that handles some logic on fieldChanged for Sales Order records.
This includes setting some fields as mandatory/non-mandatory according to certain criteria.
It works perfectly, except when I attempt to set a Netsuite System field (such as 'memo') as mandatory/non-mandatory.
Nothing happens, and no error.
The code used on all fields is context.currentRecord.getField({fieldId: 'memo'}).isMandatory = true;
Does anyone know why this issue would occur, or know of any workaround?
Many thanks!
Giles

try this
var memo = context.currentRecord.getField({fieldId: 'memo'});
memo.isMandatory = true;

Related

Codeigniter: How to handle database error?

I'm creating a web application using codeigniter and postgresql. I have this inside my database:
user
id name
unique(name)
When someone try to register with the same name, i get an error. How can i handle them, without displaying the codeigniter's error and showing instead my custom error?
If i set $db['default']['db_debug'] = FALSE; i don't get any error of course, but is there a way to handle the db error or should i check myself if the table already contains an entry with that same name?
Use Codeigniters form validation class. is_unique[table.columnName]. This will do the work for you. Below is an example
$this->form_validation->set_rules('name', 'Name', 'is_unique[table_name.Name]');
Then just set a custom message referencing the is_unique validation like below
$this->form_validation->set_message('is_unique', 'Name already exists');
I dont know anything by codeigniter, but im going to assume the principle works the same:
You first make a query like SELECT id FROM tablename WHERE name='SomeName' LIMIT 1, then you check the number of rows. This kind of checking is fairly normal. Control as much as you (sensebly) can to avoid errors down the road.
Zero rows? Safe to insert. Not zero rows? Display something like 'username allready taken'.
Example with some code:
$check = mysqli_query("SELECT id FROM tablename WHERE name='SomeName' LIMIT 1");
if( $check->num_rows!==0 ){
echo 'Username allready taken'; // echo is bad, you should process this better, but this is easy demo
}
else{
// Your normal inserting code goes here.
}
Like Martijn said, it is a solution.
CI doesn't throw exception, so when you perform a query, it will return NULL if the statement fails.
You may want to see CodeIgniter - how to catch DB errors?

Getting new PurchId via .NET BusinessConnector

I am trying to find a .NET BusinessConnector equivalent call for the below line:
PurchId = NumberSeq::newGetNum(SalesParameters::numRefSalesId()).num();
I am manually entering purchase order information into the purchase order table, which is fine, but the problem lies in the fact that it is the PurchID that ties purchase table (PURCHTABLE) and the individual purchase order lines (PURCHLINE) is the PURCHID field, which is not automatically populated when saving a purchase order.
Currently I am:
ax.TTSBegin();
axRecord.set_Field("ORDERACCOUNT", purchaseOrder.OrderAccount);
(etc)
axRecord.Insert();
However, while this will insert a record into the database, it has no purchID, which has to be generated. You need a purchID to link the purchase line items in. I found the above code (second line) for X++, but does anyone know of a .NET BusinessConnector call that can be used instead?
Any assistance would be greatly appreciated.
Regards,
Steve
I would go for a change in the insert() method of the PurchTable table:
if (!purchTable.PurchId)
purchTable.PurchId = NumberSeq::newGetNum(purchParameters::numRefPurchId()).num();
Placed after the ttsbegin.
This to avoid complicated C# code. You probably could do it in C# code alone using CallStaticClassMethod and cousins, but it is better do put the buisness logic on the X++ side.
See How to: Call Business Logic Using .NET Business Connector.
Be sure to execute inside a TTSBegin/ TTSCommitblock, otherwise you will get error error messages like this one.
// ax is a reference to an "Axapta" business connector object
var numRef = ax.CallStaticRecordMethod("SalesParameters", "numRefSalesId");
var numSeq = (AxaptaObject)ax.CallStaticClassMethod("NumberSeq", "newGetNum", numRef);
var purchId = numSeq.Call("num");

Read Only Error on incident form in plugin CRM 2011 Plugin

I have a problem, which I'm really trying to figure out how I could best solve this. I have read various posts regarding this error and seems you can avoid this by using JavaScript by using:
Xrm.Page.getAttribute("name").setSubmitMode("always");
which doesn't work for me or inside the plugin. Now to my problem, I have an update plugin firing on my incident form, which updates some fields. However when I try to resolve the case or cancel it I get the error from my update plugin "The object cannot be updated because it is read-only" I have tried the following and would appreciate if somone could advice me what I'm doing wrong. My code for a plugin I'm registering as SetState on pre-operation against the incident form:
SetStateRequest setState = new SetStateRequest();
setState.EntityMoniker = new EntityReference();
setState.EntityMoniker.Id = incidentId; //Id which needs to be resolved/canceld
setState.EntityMoniker.Name = "statecode";
setState.EntityMoniker.LogicalName = "incident";
setState.State = new OptionSetValue();
setState.Status = new OptionSetValue();
SetStateResponse setStateResponse = (SetStateResponse)service.Execute(setState); }
On the state and status I'm quite confused to what value I have to set it to. I'm just getting an error when my incident is on Active and I'm trying to resolve and cancel the case. I would appreciate if someone could help me out here. Thanks in advance.
I think there are a few areas of confusion in your post...
Xrm.Page.getAttribute("name").setSubmitMode("always");
This is clientside code and will never have any bearing on the behaviour of your (serverside) plugin. It merely forces an attribute on the form to be submitted whether it has changed or not, during a save. If the record is in a read-only state, it will not change that fact.
I'm not at all clear what you are trying to acheive in your code. You mention that an update plugin is failing; you have posted code which would attempt to set the state of the incident to something (as #glosrob suggests, you are not providing any values in the OptionSetValue objects for State and Status so as you might already know, the code you have posted is invalid); you then state that you have registered your plugin on the SetState request. This means that it would fire if the user tries to set the state of the incident. Given that your code is itself trying to set the status of the incident, I'm not sure that it makes sense...
It sounds like what you want to do is, on update of an incident, set certain values. If the incident is in a read-only state, make it readable first, and then update the values. Do you then need to restore the state of the entity to it's former state? It sounds awkward and might perhaps suggest that there is a better way to meet your core requirement.
Maybe start with what you are trying to achieve and we can work from there :)
You should remove
setState.EntityMoniker.Name = "statecode";
from your code. This field Name has other purpose.
Also, you should add
setState.State.Value = 1;
setState.Status.Value = -1;

get attribute from children on 2000 products

I'm using a script to generate a csv file for another site.
I am getting all products and on configurable ones I add in description some attributes.
Here is the code inside the function called on each configurable:
$children_ids = $product->getTypeInstance()->getUsedProductIds();
foreach($children_ids as $child_id){
$child = Mage::getModel('catalog/product')->load($child_id);
$attributeValue = $child->getAttributeText($attributeLabel);
$child_qty = (int)$child->getStockItem()->getQty();
$mage_size[$attributeValue] = $child_qty;
$simple_qty += $child_qty;
}
I noticed that on large amount of products somehow the output suddenly stop without getting all. I tested with and without this code. Without I get as expected.
I have set_time_limit(0);
But no clue why my script terminate before getting information from all products.
Any ideea whay may couse this behaviour?
It's not a proper solution but works on my script.
I added
ini_set('memory_limit', '512M');
and works fine. I know 512 is way too much but just to be sure and to prevent that behaviour in the future when will be more products.
You would both have to increase the memory limit and PHP's execution time - magento is freakin' resource hungry.
I also generate product csv's with a custom script. I would recommend to run these kind of tasks from the command line.

MS CRM QueryExpression ConditionExpression w/ CRMBoolean type

I'm using Microsoft's CRM software (4.0) and I'm trying to build a query expression. It works fine with querying only String values, but now I need to include a field that is of type CRMBoolean. I should also mention I'm querying custom entities.
So previously, in my query I would only search by a few fields, but they were all of type String. Now I need to add another ConditionExpression for a CRMBoolean. The type of custom entity I'm searching for has a field called "Condition" - which will either have a value of "true" or "false". In CRM the attribute is defined as a bit, but I didn't think that would make a difference.
Here is my code I'm trying to use to find records that have a condition of "true":
oCondition = New ConditionExpression()
oCondition.AttributeName = "myEntity_condition"
oCondition.Operator = ConditionOperator.Like
Dim bool As New CrmBoolean
bool.Value = True
oCondition.Values = New Object() {bool}
listConditions.Add(oCondition)
I don't get an error, but nothing really happens. The number of records that is returned never changes one way or another. Has anyone done this before?
Thanks in advance!
Instead of putting a CrmBoolean object in the oCondition.Values array, just put a regular true/false boolean. I would also concur with benjynito on changing it to ConditionOperator.Equals instead of Like.
I don't know how the like operator is suppose to behave on a boolean. I wonder if its being ignored. Try ConditionOperator.Equal.

Resources