It is possible to create an "empty" Object and create Object properties on the fly in Classic ASP?
Take this JavaScript example:
var sample = new Object();
sample.prop = "Object property";
sample.prop2 = "Another property";
What is the Classic ASP equivalent? Do I have to write a class with getters and setters?
yes you need to create a class for that
have a look at
http://www.codeguru.com/csharp/.net/net_asp/tutorials/article.php/c19317/Object-Oriented-ASP-Using-Classes-in-Classic-ASP.htm
JScript is prototype oriented, so you don't need to create a class to add members to an instance. You can add new members to the new object instance on the fly:
var sample = {};
sample.prop = "Object property";
sample.prop2 = "Another property";
Related
I have a customization where I'm creating projects in code using the ProjectEntry graph and
the PMProject DAC:
//create the project graph...
ProjectEntry projentry = PXGraph.CreateInstance<ProjectEntry>();
pmproj = new PMProject();
//Set the ProjectID:
pmproj.ContractCD = "000001"; //Project preferences is set to allow manually created project CDs...
//The template ID...
var tmplt = (PMProject)PXSelect<PMProject,
Where<PMProject.contractCD, Equal<Required<PMProject.contractCD>>>>.Select(Base, "00TEMPLATE01");
pmproj.TemplateID = tmplt.ContractID;
//The description....
pmproj.Description = "Test description";
//Now save the new project...
pmproj = projentry.Project.Insert(pmproj);
projentry.Persist();
It's not picking up the template tasks. Is there something else I need to do to get those tasks to come into the project?
There is a separate method that you need to trigger to populate settings from a project template.
DefaultFromTemplate(Project.Current, newTempleteID, DefaultFromTemplateSettings.Default);
It is executed automatically when you do that from UI, but if you do that from cod you need to do it manually.
Try this alternative approach to the sequence in which the values are entered in the Cache:
ProjectEntry projentry = PXGraph.CreateInstance<ProjectEntry>();
pmproj = new PMProject();
pmproj.ContractCD = "000001";
pmproj = projentry.Project.Insert(pmproj);
var tmplt = (PMProject)PXSelect<PMProject,
Where<PMProject.contractCD, Equal<Required<PMProject.contractCD>>>>.Select(Base, "00TEMPLATE01");
pmproj.TemplateID = tmplt.ContractID;
projentry.Project.Update(pmproj);
pmproj.Description = "Test description";
projentry.Project.Update(pmproj);
projentry.Actions.PressSave();
I have a base class "Entity" and a derived class "Site" or "Group". Both are marked as serializable. I am sending them to the service bus and retrieving as follows. None of the inherited properties are set after reading, however; it's as if they are ignored during deserialization. Any way I can get these to work or do I need to write my own XML deserializer?
var queueEntity = new QueueEntity(e); // e is Entity, Site
var brokered = new BrokeredMessage(queueEntity);
QueueContext.QueueClient.Send(brokered);
Worker role
var message = receivedMessage.GetBody<QueueEntity>();
var e = message.Entity; // this only has derived class property values set
Thanks!
You could serialize it using existing serializers and pass into BrokeredMesdage as a Stream. On the receiving side do the other way around, serializing from a Stream into your object.
I got this error during execute, could anyone give suggestion? Thanks
OrganizationRequest oreq = new OrganizationRequest();
oreq.RequestName = "RetrieveAllEntities";// please google for available Request Names
oreq.Parameters = new ParameterCollection();
oreq.Parameters.Add(new KeyValuePair<string, object>("EntityFilters", EntityFilters.Entity));
oreq.Parameters.Add(new KeyValuePair<string, object>("RetrieveAsIfPublished", false));
OrganizationResponse respo = orgProxy.Execute(oreq);
"The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter schemas.microsoft.com/xrm/2011/Contracts/Services:ExecuteResult. The InnerException message was 'Error in line 1 position 727. Element 'schemas.datacontract.org/2004/07/System.Collections.Generic:value' contains data of the 'schemas.microsoft.com/xrm/2011/Metadata:ArrayOfEntityMetadata' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'ArrayOfEntityMetadata' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details."
Add a reference to Microsoft.Crm.Sdk.Proxy and Microsoft.Xrm.Sdk. Visual Studio may tell you that you need to add an additional couple System.* references - add them.
Use this code:
IOrganizationService service = GetCrmService(connectionString); //This is a helper, just need to setup the service
var request = new Microsoft.Xrm.Sdk.Messages.RetrieveAllEntitiesRequest()
{
EntityFilters = Microsoft.Xrm.Sdk.Metadata.EntityFilters.All,
RetrieveAsIfPublished = false
};
var response = (Microsoft.Xrm.Sdk.Messages.RetrieveAllEntitiesResponse)service.Execute(request);
Get it work finally there is two KnownTypeAttribute need to be added to the proxy class
**[System.Runtime.Serialization.KnownTypeAttribute(typeof(EntityMetadata[]))]**
public partial class OrganizationRequest : object, System.Runtime.Serialization.IExtensibleDataObject
....
**[System.Runtime.Serialization.KnownTypeAttribute(typeof(EntityMetadata[]))]**
public partial class OrganizationResponse : object, System.Runtime.Serialization.IExtensibleDataObject
Thank you for help.
Dynamics CRM 2011 on premise
I can barely believe I can't find this out by Googling. MSDN is useless.
Here is some C# from a plugin:
integ_creditpayment creditpayment = new integ_creditpayment();
creditpayment.integ_Amount = totalPay;
//set more properties
context.AddObject(creditpayment);
context.SaveChanges();
Now I want to get the value of the id field in integ_creditpayment.
Can I get this immediately from creditpayment.id? (As in, does context.SaveChanges() cause the creditpayment variable to be updated with the new id?)
I'm assuming your real code is more complicated, but there is no need to use the context in your example code:
integ_creditpayment creditpayment = new integ_creditpayment();
creditpayment.integ_Amount = totalPay;
//set more properties
creditpayment.Id = service.Create(creditpayment);
You can also use a type initializer and get rid of your object all together if you'd like:
Guid id = service.Create(new integ_creditpayment
{
integ_Amount = totalPay;
});
service in this case is of type IOrganizationService
After the SaveChanges() you can get the record id with:
Guid justCreatedId = creditpayment.Id;
I am very confused, i am trying in vain to queue up multiple inserts i have thousands of adds to do so i only want to really do the database once.
I am using .net 4 and entity framework 4 and also added reference to system.data.objects
but i still have no overload available for SaveChanges
here is my code:
using (TransactionScope scope = new TransactionScope())
{
using (myDbContext context = new myDbContext)
{
foreach (var p in model)
{
var tempProduct = new Products();
// set a loopable list of available products
IEnumerable<MerchantProductFeedMerchantProd> prod = p.prod;
foreach (var i in prod)
{
var prodText = i.text.FirstOrDefault();
var prodUri = i.uri.FirstOrDefault();
var prodPrice = i.price.FirstOrDefault();
FillTempProduct(feedId, i, tempProduct, supplierId, feedInfo, prodPrice, prodText,
prodUri);
context.Products.Add(tempProduct);
context.SaveChanges(false); // no overload
}
scope.Complete();
context.AcceptAllChanges(); //acceptallchanges not referenced ??
}
}
this is really battering my head now, so any help would be much appreciated.
thanks
Because you are using DbContext API and these methods are from ObjectContext API. DbContext API is simplified = it is only for simple requirements. If you have more complex requirements you must use ObjectContext API by converting your DbContext to ObjectContext instance:
var objectContext = ((IObjectContextAdapter)myDbContext).ObjectContext;