Dynamic NAV 2018 Web Service: Creating Sales Order Lines gets error "Standard Code Text does not exist...." - soap

In Dynamic NAV 2018, I exposed page Sales Order (id 36) as web service, I'm following some guides to create Sales Order Header and Sales Order Lines, the Header can be created successfully, but the Sales Lines always get error "Standard Code Text does not exist..."
SOWS.Sales_Order_VS_Service testcreateSO = new SOWS.Sales_Order_VS_Service();
testcreateSO.UseDefaultCredentials = true;
SOWS.Sales_Order_VS SOEntity = new SOWS.Sales_Order_VS();
testcreateSO.Create(ref SOEntity);
SOEntity.Sell_to_Customer_No = "44094";
SOEntity.Store_No = "S9003";
SOEntity.Location_Code = "S9003";
testcreateSO.Update(ref SOEntity);
SOEntity.SalesLines = new SOWS.Sales_Order_Line[1];
SOEntity.SalesLines[0] = new SOWS.Sales_Order_Line();
testcreateSO.Update(ref SOEntity);
SOEntity.SalesLines[0].Type = SOWS.Type.Item;
SOEntity.SalesLines[0].TypeSpecified = true;
SOEntity.SalesLines[0].No = "208122";
SOEntity.SalesLines[0].Quantity = 1;
testcreateSO.Update(ref SOEntity);
System.Web.Services.Protocols.SoapException: 'The Standard Text does not exist. Identification fields and values: Code='208122''
Checking in table Sales Lines, a record of new order has been created but Type = 0 (means blank)
Document No_ Line No_ Sell-to Customer No_ Type No_ Location Code Document Type
SO210600017 10000 0 1
Please help
Solution
Instead of using only singe page Sales Order as web service, can expose page Sales Order Line as another web service, so full code as below:
SOWS.Sales_Order_VS_Service testcreateSO = new SOWS.Sales_Order_VS_Service();
testcreateSO.UseDefaultCredentials = true;
SOWS.Sales_Order_VS SOEntity = new SOWS.Sales_Order_VS();
testcreateSO.Create(ref SOEntity);
SOEntity.Sell_to_Customer_No = "44094";
SOEntity.Store_No = "S9003";
SOEntity.Location_Code = "S9003";
testcreateSO.Update(ref SOEntity);
//Using Sales Order Line page as web service from here
SOLinesWS.salesDocumentLines_Service saleslinesSV = new SOLinesWS.salesDocumentLines_Service
{
UseDefaultCredentials = true
};
SOLinesWS.salesDocumentLines saleslines = new SOLinesWS.salesDocumentLines();
saleslines.documentType = SOLinesWS.documentType.Order;
saleslines.documentTypeSpecified = true;
saleslines.documentNumber = SOEntity.No;
saleslines.type = SOLinesWS.type.Item;
saleslines.typeSpecified = true;
saleslines.number = "208122";
saleslines.quantity = 1;
saleslines.quantitySpecified = true;
saleslinesSV.Create(ref saleslines);

Related

How to do this query using Django orm?

I have a Profile model and Complain model both are connected to the inbuilt User model.I have to do a query using both in which Profile model have residence. I want to have a count, that how many complains are made from a particular residence. I can do it using SQL but I didn't know how to do it using Django.
SELECT users_profile.residence,count(user_id)from users_profile INNER JOIN chp_complain on(users_profile.user_id = chp_complain.complain_user_id)GROUP BY(user_id)
Complain Model:-
class Complain(models.Model):
complain_user = models.ForeignKey(User, on_delete=models.CASCADE)
complain_department=models.CharField(max_length=100)
complain_subject = models.CharField(max_length = 100,help_text = "Enter the complain subject")
department_head=models.CharField(max_length=100)
recepient=models.CharField(max_length=100)
complain_description=models.TextField(max_length=2000)
date_posted = models.DateTimeField(default = timezone.now)
NOT_VISITED = 'NV'
VISITED = 'V'
INPROCESS = 'IP'
COMPLETED = 'C'
status = (
(NOT_VISITED, 'NV'),
(VISITED, 'V'),
(INPROCESS, 'IP'),
(COMPLETED, 'C'),)
status=models.CharField(max_length=2,choices=status,)
Profile Model:-
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
UID =models.CharField(max_length=30,default = "000",help_text = "'Staff's fill their STAFF ID and student's fill their ROLL NO " )
MALE = 'M'
FEMALE = 'F'
Gender=((MALE, 'Male'),(FEMALE, 'Female'),)
Gender=models.CharField(max_length=6,choices=Gender,default=MALE,)
FIRST = '1st'
SECOND = '2nd'
THIRD = '3rd'
FOURTH = '4th'
NGH = 'NGH'
NON_HOSTELER = 'Non_hosteler'
TEACHER_QUARTER = 'Teacher_quarter'
residence = ((FIRST, 'First'),(SECOND, 'Second'),(THIRD, 'Third'),(FOURTH, 'Fourth'),(NGH,'NGH'),(NON_HOSTELER, 'Non_hosteler'),(TEACHER_QUARTER,'Teacher_quarter'))
residence = models.CharField(max_length=20,choices=residence,default=FIRST,)
room_no=models.CharField(max_length=10,default = "000")
I want to have a count, that how many complains are made from a particular residence you can write:
Complain.objects.values('complain_user__profile__residence').annotate(complains_count=Count('id'))
In your SQL query:
SELECT users_profile.residence,count(user_id)from users_profile INNER JOIN chp_complain on(users_profile.user_id = chp_complain.complain_user_id)GROUP BY(user_id)
You calculate how many users filed complaints from a particular residence. It can be calculated as follows:
User.objects.values('profile__residence').annotate(Count('id'))

Tags are appearing in left of the document in embedded Signing using template

``code` DocuSignTK.Recipient recipient = new DocuSignTK.Recipient();
recipient.Email = signer_email; // This person will use embedded signing. If you have his
// email, supply it. If you don't, use a fake email that includes your
// ClientUserID. Eg embedded_signer_{ClientUserID}#your_company.com
recipient.UserName = signer_name;
recipient.ID = 1;
recipient.Type_x = 'Signer';
recipient.RoutingOrder = 1;
recipient.RoleName = 'Signer1';
// We want this signer to be "captive" so we can use embedded signing with him
recipient.CaptiveInfo = new DocuSignTK.RecipientCaptiveInfo();
recipient.CaptiveInfo.ClientUserID = signer_user_id; // Must uniquely identify the
// Create the recipient information
DocuSignTK.ArrayOfRecipient1 recipients = new DocuSignTK.ArrayOfRecipient1();
recipients.Recipient = new DocuSignTK.Recipient[1];
recipients.Recipient[0] = recipient;
DocuSignTK.ArrayOfTemplateReferenceRoleAssignment Roles = new DocuSignTK.ArrayOfTemplateReferenceRoleAssignment();
Roles.RoleAssignment = new DocuSignTK.TemplateReferenceRoleAssignment[1];
DocuSignTK.TemplateReferenceRoleAssignment role = new DocuSignTK.TemplateReferenceRoleAssignment();
role.RoleName = 'Signer1';
role.RecipientID = 1;
Roles.RoleAssignment[0] = role;
// Create the template reference from a server-side template ID
DocuSignTK.TemplateReference templateReference = new DocuSignTK.TemplateReference();
templateReference.Template = 'd0d80082-612b-4a04-b2a1-0672eb720491';
templateReference.TemplateLocation = 'Server';
templateReference.RoleAssignments = Roles;
// Construct the envelope information
DocuSignTK.EnvelopeInformation envelopeInfo = new DocuSignTK.EnvelopeInformation();
envelopeInfo.AccountId = account_Id;
envelopeInfo.Subject = 'Subject';
envelopeInfo.EmailBlurb = 'Email content';
// Make the call
try {
//DocuSignTK.EnvelopeStatus result = api_sender.CreateAndSendEnvelope(envelope);
// Create draft with all the template information
DocuSignTK.ArrayOfTemplateReference TemplateReferenceArray = new DocuSignTK.ArrayOfTemplateReference();
TemplateReferenceArray.TemplateReference = new DocuSignTK.TemplateReference[1];
TemplateReferenceArray.TemplateReference[0] = templateReference;
DocuSignTK.EnvelopeStatus result = api_sender.CreateEnvelopeFromTemplates( TemplateReferenceArray, recipients, envelopeInfo, true);
envelope_id = result.EnvelopeID;
System.debug('Returned successfully, envelope_id = ' + envelope_id );
} catch ( CalloutException e) {
System.debug('Exception - ' + e );
error_code = 'Problem: ' + e;
error_message = error_code;
} `code``
I am integrating Docusign for embedded signing. I am using SOAP API and used method CreateEnvelopeFromTemplates . Template I created is having some fields/Tabs. But once I open signing url these fields are located on side of the document instead of the location which I sent in template.
I have also assigned Role name for recipient but it is not working. Please help.
Click here to see screenshot
Here is the C# code to create an envelope from template using the DocuSign SOAP Api. Documentation here
string apiUrl = "https://demo.docusign.net/api/3.0/api.asmx";
string accountId = "Enter accountId"; //
string email = "Enter email";
string userName = "Enter intergrator key";
userName += email;
string _password = "Enter password";
var apiClient = new DocuSignTK.APIServiceSoapClient("APIServiceSoap", apiUrl);
apiClient.ClientCredentials.UserName.UserName = userName;
apiClient.ClientCredentials.UserName.Password = _password;
// Construct all the recipient information
var recipients = new DocuSignTK.Recipient[1];
recipients[0] = new DocuSignTK.Recipient();
recipients[0].Email = "recipientone#acme.com";
recipients[0].UserName = "recipient one";
recipients[0].Type = DocuSignTK.RecipientTypeCode.Signer;
recipients[0].ID = "1";
recipients[0].RoutingOrder = 1;
recipients[0].RoleName = "Signer1";
var roles = new DocuSignTK.TemplateReferenceRoleAssignment[1];
roles[0] = new DocuSignTK.TemplateReferenceRoleAssignment();
roles[0].RoleName = recipients[0].RoleName;
roles[0].RecipientID = recipients[0].ID;
// Use a server-side template -- you could make more than one of these
var templateReference = new DocuSignTK.TemplateReference();
templateReference.TemplateLocation = DocuSignTK.TemplateLocationCode.Server;
// TODO: replace with template ID from your account
templateReference.Template = "d0d80082-612b-4a04-b2a1-0672eb720491";
templateReference.RoleAssignments = roles;
// Construct the envelope information
DocuSignTK.EnvelopeInformation envelopeInfo = new DocuSignTK.EnvelopeInformation();
envelopeInfo.AccountId = " ";
envelopeInfo.Subject = "create envelope from templates test";
envelopeInfo.EmailBlurb = "testing docusign creation services";
// Create draft with all the template information
DocuSignTK.EnvelopeStatus status = apiClient.CreateEnvelopeFromTemplates(new DocuSignTK.TemplateReference[] { templateReference },
recipients, envelopeInfo, false);
I downloaded a template from production and uploaded in sandbox but once I recreated similar template in Sandbox only and used it's template ID in code then it is working perfectly. Apparently, There seems to be some issue with import template utility of Docusign.

PSI update resource custom field with lookup table (Project Server)

Can someone show me a code to update a enterprise resource custom field with lookup table ? Already ran the internet looking for some sample code but did not succeed.
You can create and update a custom field with a lookup table using the below code . But we can not update or delete builtin custom fields
var projContext = new ProjectContext(projectServerUrl);
CustomFieldCollection CustomField = projContext.CustomFields;
EntityTypes Entitytype = projContext.EntityTypes;
LookupTableCollection lookupTables = projContext.LookupTables;
projContext.Load(CustomField);
projContext.Load(Entitytype);
projContext.Load(lookupTables);
projContext.ExecuteQuery();
CustomFieldCreationInformation NewfieldInfo = new CustomFieldCreationInformation();
NewfieldInfo.Id = new Guid();
NewfieldInfo.Name = "The Name";
NewfieldInfo.Description = "The Description";
NewfieldInfo.IsWorkflowControlled = true;
NewfieldInfo.IsRequired = true;
NewfieldInfo.IsEditableInVisibility = false;
NewfieldInfo.IsMultilineText = false;
LookupTable lookuptable = lookupTables.ToList().Find(x => x.Name == "LookupTableName");
projContext.Load(lookuptable);
projContext.ExecuteQuery();
NewfieldInfo.LookupTable = lookuptable;
NewfieldInfo.EntityType = Entitytype.ProjectEntity;
NewfieldInfo.FieldType = CustomFieldType.TEXT;
projContext.CustomFields.Add(NewfieldInfo);
projContext.CustomFields.Update();
projContext.ExecuteQuery();

Trying to insert QBO invoice with IPP.NET

I am attempting to insert an invoice into Quickbooks Online using IPP.NET. The problem seems to be in setting the item.
Here is a snippet of my VB code for the first line, which works fine...
Dim qboInvoiceLine1 as new intuit.ipp.data.qbo.invoiceline
qboInvoiceline1.desc="Desc1"
qboInvoiceLine1.amount=10
qboInvoiceLine1.AmountSpecified=True
If I add the following code for setting the item, I get an error forming the XML...
Dim items1 as List(Of Intuit.Ipp.Data.Qbo.Item)=New List(Of Intuit.Ipp.Data.Qbo.Item)
Dim item1 as new intuit.ipp.data.qbo.item
item1.id=new intuit.ipp.data.qbo.idtype
item1.id.value="1"
items1.add(item1)
qboInvoiceLine1.Items=items1.ToArray
I do not even understand why the item ID seems to be some kind of array or list of items. One source of documentation suggests there is an itemID property of the invoice line, but this does not seem to be the case. Can anyone give me code for setting the itemID for an invoice line?
ItemsChoiceType2[] invoiceItemAttributes = { ItemsChoiceType2.ItemId, ItemsChoiceType2.UnitPrice,ItemsChoiceType2.Qty };
object[] invoiceItemValues = { new IdType() { idDomain = idDomainEnum.QB, Value = "5" }, new decimal(33), new decimal(2) };
var invoiceLine = new InvoiceLine();
invoiceLine.Amount = 66;
invoiceLine.AmountSpecified = true;
invoiceLine.Desc = "test " + DateTime.Now.ToShortDateString();
invoiceLine.ItemsElementName = invoiceItemAttributes;
invoiceLine.Items = invoiceItemValues;
invoiceLine.ServiceDate = DateTime.Now;
invoiceLine.ServiceDateSpecified = true;
listLine.Add(invoiceLine);

How do I test a trigger with an approval process?

I have a trigger which initiates an approval process when certain criteria are met:
trigger AddendumAfterIHMS on Addendum__c (after update) {
for (integer i = 0; i<Trigger.new.size(); i++){
if(Trigger.new[i].RecordTypeId != '012V0000000CkQA'){
if(Trigger.new[i].From_IHMS__c != null && Trigger.old[i].From_IHMS__c == null){
ID addendumId = Trigger.new[i].Id;
// Start next approval process
Approval.ProcessSubmitRequest request = new Approval.ProcessSubmitRequest();
request.setObjectId(addendumId);
Approval.ProcessResult requestResult = Approval.process(request);
}
}
}
}
It works perfectly, but now i need to create a test class for it. I have created a class which brings the code up to 75% coverage, which is the minimum, but I'm picky and like to have 100% coverage on my code. The test class I have now gets stuck on the line request.setObjectId(addendumId); and doesn't move past it. The error I receive is:
System.DmlException: Update failed. First exception on row 0 with id a0CV0000000B8cgMAC; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AddendumAfterIHMS: execution of AfterUpdate
Here is the test class that I have written so far, most of the class actually tests some other triggers, but the important line which is throwing the error is the very last line update addendumTierFeature;
#isTest
private class AddendumTest {
static testMethod void myUnitTest() {
// Query Testing Account, will need ID changed before testing to place into production
Account existingAccount = [SELECT Id FROM Account LIMIT 1];
Model__c existingModel = [SELECT Id FROM Model__c WHERE Active__c = TRUE LIMIT 1];
Pricebook2 existingPricebook = [SELECT Id,Name FROM Pricebook2 WHERE IsActive = TRUE LIMIT 1];
List<Contact> existingContacts = [SELECT Id,Name FROM Contact LIMIT 2];
Contact existingContactPrimary = existingContacts[0];
Contact existingContactSecondary = existingContacts[1];
Opportunity newOpportunity = new Opportunity(
Name = 'New Opportunity',
Account = existingAccount,
CloseDate = Date.today(),
Order_Proposed__c = Date.today(),
StageName = 'Branch Visit - Not Responding',
Opportunity_Follow_Up__c = 'Every 120 Days',
LeadSource = 'Farm Lists',
Source_Detail__c = 'FSBO',
Model_Name__c = existingModel.Id,
Processing_Fee__c = 100.50,
Site_State__c = 'OR',
base_Build_Zone__c = 'OR',
Pricebook_from_Lead__c = existingPricebook.Name
);
insert newOpportunity;
//system.assert(newOpportunity.Id != null);
ID newOppId = newOpportunity.Id;
OpportunityContactRole contactPrimary = new OpportunityContactRole(
Role = 'Primary',
IsPrimary = true,
OpportunityId = newOppId,
ContactId = existingContactPrimary.Id
);
OpportunityContactRole contactSecondary = new OpportunityContactRole(
Role = 'Primary',
IsPrimary = false,
OpportunityId = newOppId,
ContactId = existingContactPrimary.Id
);
insert contactPrimary;
insert contactSecondary;
newOpportunity.Name = 'Different - Updating';
newOpportunity.Order_Accepted__c = Datetime.now();
update newOpportunity;
Addendum__c addendumCustomOption = new Addendum__c(
RecordTypeId = '012V0000000CkQA', //Pre Priced Custom Option
Opportunity__c = newOppId,
Item_Pre_Priced_Description__c = 'a1eV00000004DNu',
Reason__c = 'This is a reason',
Item__c = 'This is an Item',
Quantity__c = 1
);
Addendum__c addendumTierFeature = new Addendum__c(
RecordTypeId = '012V0000000Cjks', //Tier Feature
Opportunity__c = newOppId,
Category__c = 'Countertops',
Reason__c = 'This is a reason',
Item__c = 'This is an Item',
Quantity__c = 1
);
insert addendumCustomOption;
insert addendumTierFeature;
addendumCustomOption.Quantity__c = 2;
addendumTierFeature.Quantity__c = 2;
update addendumCustomOption;
update addendumTierFeature;
update newOpportunity;
addendumTierFeature.To_IHMS__c = system.now();
update addendumTierFeature;
addendumTierFeature.From_IHMS__c = system.now();
update addendumTierFeature;
}
}
Any help on this matter would be greatly appreciated. I believe the problem is in the way I am testing the approval process start. Is there by chance a special testing function for this?
After fiddling around for a little while I discovered that the error was actually tied into my approval process. I kept digging into the error logs until I got to the error: caused by: System.DmlException: Process failed. First exception on row 0; first error: MANAGER_NOT_DEFINED, Manager undefined.: []. This phrase indicates that there is no one defined for the next step in my approval process.
When I created the opportunity, I did not set the owner and somehow this created an opportunity which had an owner without a manager. The addendum was also created without an owner/manager. So when I tried to launch the next approval process, there was no manager to send the approval to and an error was thrown.