I have an entity called product. There is a field called item price.
Now i have created 100 products. I want to SUM (mathematical operation) all the products "item price" field and display it in an other entity called opportunity field called "total items price".
Besides this if i create 101 product and it's "item price", "total items price" field in opportunity automatically up date itself.
So for i have SUMMED to fields of a form. e.g there is a field A and field B, multiplying field A with 3.14 and displaying result in field B.
Here is the Code.
function SumField() {
var price = Xrm.Page.getAttribute("new_price");
var total_price = Xrm.Page.getAttribute("new_total_price");
if(price.getValue() != null) {
var newValue = price.getValue() * 3.14;
total_price.setValue(newValue);
// Make sure the changes are saved back to the server - in CRM 4.0, this was crmForm.new_fieldname.ForceSubmit = true;
Xrm.Page.getAttribute("new_total_price").setSubmitMode("always");
}
}
JavaScript will not work in this scenario, atleast it will not be the most optimum solution.
Rather than handling it with JavaScript write a Plugin that fires on change in Product entity and updates the desired record of opportunity entity. (I am considering that there will be few products related to one opportunity i.e. 1:N relationship)
In case you want that change in one product will update values in all records Opportunity create a another entity say "Configuration" which will hold this value and show it on Opportunity form using JavaScript (reason being: If one product record creation updates all records of Opportunities it will impact performance of CRM)
You have some possibilities, the best choice depends of your technology expertise:
Workflow - launch workflow when the field new_total_price changed and update the opportunity related. For this you don't need any known of programming languages
Plugin - in update of your product entity you can update the related opportunity. You need know C# or VB .NET
Javascript - One solution is onload of opportunity you check if product related has (you case use FetchXML or OData for example) the new_total_price filled, with that information you can update your opportunity.
There is more alternatives but you have here some options.
Related
I have a form and one input item must be unique. (It is primary key.) When I click to add, I get an error message. It is OK, but I want to get this error message when I set the item's value not when I filled the whole forms and click on the ADD button.
For example I have a COUNTRY table with a COUNTRY_ID column. The COUNTRY_ID column must be unique.
I created a hidden page item: C_ID_CHECK
I created a dynamic action:
Event --> change
Selection type --> Item
Item --> P6_COUNTRY_ID
I created a true dynamic action.
Execute Server-side Code --> pl/sql
DECLARE pk_error NUMBER;
BEGIN
SELECT 1 INTO pk_error
FROM COUNTRY
WHERE COUNTRY_ID = :P6_COUNTRY_ID;
:P6_C_ID_CHECK := 'Y';
EXCEPTION
WHEN others THEN
:P6_C_ID_CHECK := 'N';
END;
Items to submit --> :P6_COUNTRY_ID
Items to Return --> :P6_C_ID_CHECK
So if the new COUNTRY_ID already exsist, then C_ID_CHECK value is Y, otherwise N.
I created another true dynamic action. Action --> Alert
Client-side Condition:
Type --> Item = Value
Item --> P6_C_ID_CHECK
Value --> Y
So if the first dynamic action put Y value to the P6_C_ID_CHECK item, then this dynamic action raise an alert if the value is Y.
When I tried it I got this message:
Ajax call returned server error ORA-20987: APEX - Attempt to save item P6_COUNTRY_ID in session state during show processing. Item protection level indicates:
Item may be set when accompanied by a "session" checksum.
No checksum was passed in or the checksum passed in would be suitable for an item with protection level "(No checksum was provided)".
Note: End users get a different error message. - Contact your application administrator. for ajax_set_session_state.
What could go wrong? Is this a good way to get immediate notification if I try to insert wrong data or is there any other / easier way?
I agree with Koen that this is not a good design.
But to answer your question, the error message is saying that you have "item protection" turned on. Edit your P6_C_ID_CHECK component and set Value Protected to "No". That should allow you to update it from a Dynamic Action.
See this similar question, and the documentation for "hidden" item types.
This is not the correct way of handling primary keys in apex. Always have the database handle your primary keys, either by (1) using a trigger and a sequence - this is the old way or (2) using an identity column - this is the more modern way.
Then in your application, let the native form processes do the work for you. Mark the primary key item in your form as "Primary Key" and you're done.
Test this out in a sample app on the emp/dept sample data. Create a new page of type Interactive Report and check "include form". Use "EMP" as the table. This will generate a report and form that handles both creation of new records or updating existing records. There never is a need for a check if the PK is unique.
Here is a very complete blog from the apex dev team explaining the form functionality.
I have a need to be able to update a large number of memorized transactions, namely sales orders. So, the transactions are generated, but there may or may not be certain fields that need to be updated each time they are generated. A coworker of mine tried a mass update, and I tried doing some scripted updates, and we both were greeted with the same error: MEMORIZED_TRANS_ERROR - Attempting to access memorized transaction as a non-memorized transaction. Is there a way to accomplish such a mass edit/update and avoid this error?
Would help if you showed some code but a guess is you are using the wrong record type. It should be memdoc. The help topic Memorized Transaction Definition has example code.
Sample Code
Memorized transaction definitions can only be created in the NetSuite user interface. The example script below first loads an existing memorized transaction definition with ID 2. Then, it sets the Action field to “Reminder”, and sets the Next Transaction Date in the Custom Dates subtab to 12/12/2020. It saves this date, and then saves the memorized transaction definition.
var r = nlapiLoadRecord('memdoc', 2)
r.setFieldValue('action', 'REMINDER')
r.selectNewLineItem('customdates')
r.setCurrentLineItemValue('customdates', 'nextdate', '12/12/2020')
r.commitLineItem('customdates')
var id = nlapiSubmitRecord(r);
I have a field where I want to add a custom filter. This filter will be based on the value of a linked entity.
But, I found out that we cannot have complex queries using addCustomFilter() method.
What is the other way to do the same?
Yes you can have complex queries. Build the query using FetchXml. Ok here the JS I've used. I'll explain. I have a user lookup which I filter using a custom view based on the value selected in another lookup called areas.
Create the javascript function below in the form that you want this functionality.
fetchXml is where you create the query. As you can see, I'm querying the system user entity, then crossing over to the AreaUserLink entity (join on tes_user = systemuserid) and then filtering on the tes_area field = the value inserted from the form field.
layoutXml is where you define the layout of the screen that gets displayed when the person clicks on the lookup and goes to the lookup details screen. You will need to amend those to fit your new scenario.
viewId is just a random GUID that you need to provide so that CRM can store it. It will need to be unique.
In the code below...
function AttachReviewByCustomView() {
var areaLookup = Xrm.Page.getAttribute('tes_area').getValue();
if (areaLookup == null) {
return;
}
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
"<entity name='systemuser'><attribute name='fullname' /><attribute name='systemuserid' />" +
"<order attribute='fullname' descending='false' />" +
"<filter type='and'>" +
"<condition attribute='isdisabled' value='0' operator='eq'/></filter>" +
"<link-entity name='tes_userarealink' from='tes_user' to='systemuserid' alias='ak'>" +
"<filter type='and'>" +
"<condition attribute='tes_area' operator='eq' uitype='tes_area' value='" + areaLookup[0].id + "' />" +
"</filter></link-entity></entity></fetch>";
var layoutXml = "<grid name='resultset' object='1' jump='systemuserid' select='1' icon='1' preview='1'>" +
"<row name='result' id='systemuserid'>" +
"<cell name='fullname' width='150' />" +
"</row></grid>";
var viewId = "{00000000-0000-0000-0000-000000000003}";
var viewDisplayName = "Active Users In Selected User-Area";
Xrm.Page.getControl("tes_operative").addCustomView(viewId, "systemuser", viewDisplayName, fetchXml, layoutXml, true);
}
Lastly you need to call this from two places.
1. When the form loads.
2. When the person selects a value from the dropdown field that is used in the fetchXml variable to filter.
Hope this helps.
Right now I am coding in PHP & HTML
I need to make a selection from the checkbox group
and it goes like this:
The value in the dropdown menu is retrieved from the value stored in the database in table subject. So the checkbox options will appears as (for example) Mathematics, Algebra, Calculus, English, Linguistic etc. -- I have no problem with displaying this one.
Table subject
subject_id subject_name
========== ============
1 Mathematics
2 Algebra
3 Calculus
4 English
5 Linguistic
So after that, a student can choose their subject and it will be stored in another table named student_subject where it stores the student_id and the subject_id (to store what subjects did a student chose)
Example:
table student_subject
student_id subject_id
========== ===========
1 1
1 2
1 3
2 1
2 3
Now, the student comes again to add another subject to his profile. The same checkbox option will be displayed as mentioned earlier in (1) but I would love to disabled/remove/not display the already selected option from being selectable again to avoid redundancy.
I really have no idea on how to create this function. I know there are a lot of experienced programmers and developera here so I wish you could show me the right way. Your guidance is highly appreciated.
You should not remove/disabled/not display the existing subjects.
First, you should check for existing rows for student_subject table and render it in HTML checkbox as selected.
Second, while student makes changes for subject selection in edit mode, check with the database rows with student and subject ids in a loop.
If submitted subject id for the student is not available in the database, insert that value to the table.
If submitted subject id for the student is available in the database, do nothing with it.
Check for the removed subject from submitted values with the database, and delete from the database.
If you want to disable existing subjects, use readonly to the checkbox if the subject is assigned to the student.
This is just an idea:
On your #2 where a table will store student_id and subject_id, I think it's best that whenever you store value to subject_id- you just serialize the value by storing it on an php array in that way you can iterate the whole array if the field was checked or not.
Json_encode is also good since it will be a string and same as serialize
Example:
Student_id Subject_ID
999-0518 a:{this is the serialize value };
Then when you query the result it will be serialize, then use unserialize function and do a loop to iterate the results, same goes when you json_encode; just perform json_decode() function and perform loop.
You can use a query which only picks up subjects which ID isn't in student_subject.
It would look something like:
SELECT * FROM `subject`
WHERE `subject_id` NOT IN (
SELECT `subject_id` FROM `student_subject` WHERE `student_id` = '1'
)
(you can ommit the inner where clause if you don't want this to be user specific)
and then build the <select> element based on the array returned from it.
Salesforce allows you to extend Object definitions by using Record Types. Is there a quick and easy way to allow users to transition groups of Objects from one Record Type to another? In my case, I will be keeping track of students as they progress through the undergraduate student life cycle from applicant to alumnus. It makes sense to me to keep track of the different phases of the student life cycle as Record Types so that I can create custom interfaces/viewing permissions/business logic for each phase. I was hoping to be able to create a custom button or link to do this as per this example from Salesforce:
Salesforce: Getting Started With Buttons and Links.
However I have had no luck querying the RecordType object using the Ajax toolkit to find out which RecordTypeId I will need to update the Object to. (I am rather new to JavaScript so it may simply be my inexperience that's getting in the way. I would be happy to post code samples of what I've tried so far if anyone asks.)
On the IdeaExchange someone mentioned that you can just include the RecordType field in the object's custom layout page (IdeaExchange: Provide a Means of Changing Record Types), but this does not seem like a reasonable solution for managing hundreds of students.
Using a workflow or a trigger does not seem like a reasonable solution either because those apparently require you to update a record or create a new one. Students should be able to transition at any time, independently of updates or new additions.
SO likes it when you mention other things that your issue could pertain to, but I think those areas are pretty self-explanatory here; this issue is relevant any time you might like to programatically transition between different record types.
What you want is probably not the RecordType object itself, but rather the RecordTypeId field on your object you are using to track students which looks up to that RecordType object. For example, to find the record type of a given student, the SOQL would look like:
SELECT RecordTypeId FROM Student__c WHERE Id = {some id}
and then if you wanted to update the record, you could change the value of the RecordTypeId like this:
var student = new sforce.SObject("Student__c");
student.Id = '{some id}';
student.RecordTypeId = '{new record type id}';
result = sforce.connection.update([student]);
To find the eligible RecordTypeIds for a given object type, you can either query the RecordType object and filter on the SObjectType column, or just call describeSObject(Student__c) and inspect the RecordTypeInfos node in the result.