Trying to delete a Miscellaneous Log Entry via eConnect - possible - dynamics-gp

I have a snippet of code that creates one or more Miscellaneous Log Entries via eConnect. If the code fails to create an entry, then all successfully created entries should be deleted.
E.g. (pseudo-code)
List<string> xmlDocs = new List<string>();
try
{
for (int index = 0; index < entries.Count; index++)
{
// Create taPAMiscLogHdrInsert
// Create taPAMiscLogLineInsert_ItemsTaPAMiscLogLineInsert[]
// Create PAMiscLogExpenseType and set the fields to above
// Generate the XML
xmlDocs.Add(econnect.CreateTransactionEntity(connectionString, xml)
}
}
catch
{
for (int index = 0; index < xmlDocs.Count; index++)
{
eConnect.DeleteTransactionEntity(connectionString. xmlDocs[index];
}
}
The DeleteTransactionEntity call fails with 'Duplicate Misc Log Entry' which makes sense since the XML from the CreateTransactionEntity call contains HdrInsert nodes.
This leads me to believe that you cannot programmatically delete Miscellaneous Log Entries, but I thought I'd ask.
Anyone know if this is possible?

Related

How to use PXRedirectToUrlException in Acumatica with two URLs

The sample code below will only create a new tab for the first URL. The goal is to have Acumatica create two separate tabs for two different URLs.
int countFirst = 3;
int countSecond = 4;
if(countFirst > 0) {
throw new PXRedirectToUrlException(firstUrl, PXBaseRedirectException.WindowMode.New, "First");
}
if(countSecond > 0) {
throw new PXRedirectToUrlException(secondUrl, PXBaseRedirectException.WindowMode.New, "Second");
}
Being that these are exceptions, the second line of code will not be executed. Perhaps you can try catching the first and if that does not work then maybe try pushing both through a PXLongOperation to get each into its own thread.

How do I transfer rich text attachments from one document to another

I have 2 documents which are supposed work in such a way to be able to transfer files between them. However, it doesn't work. The exception I get is Exception occurred calling method NotesDocument.save() Notes error: One or more of the source document's attachment are missing. Run Fixup to delete the document in the source database. This happens after I try to call save() function on the document to which I've just transfered files from the first.
The functions are below:
function transferFiles(docToGetFrom, docToTransferTo, fileFieldFromFirstName, fileFieldFromSecondName)
{
var rit1:NotesRichTextItem = getFirstNotesRichTextItem(docToGetFrom, fileFieldFromFirstName);
docToTransferTo.copyItem(rit1, fileFieldFromSecondName);
deleteAllFilesFromDocument(docToGetFrom, fileFieldFromFirstName);
docToTransferTo.save();
}
function getFirstNotesRichTextItem(documentToGetFrom, fileFieldName)
{
if (documentToGetFrom == null)
{
return(null);
}
if (!documentToGetFrom.hasItem(fileFieldName))
{
return(null);
}
var rit1:NotesRichTextItem = documentToGetFrom.getFirstItem(fileFieldName);
return rit1;
}
function deleteAllFilesFromDocument(documentToDeleteFrom, fileFieldName)
{
var arr = getAllEmbeddedObjects(documentToDeleteFrom, fileFieldName);
for(var i = 0; i < arr.length; i++)
{
arr[i].remove();
}
documentToDeleteFrom.save();
}
function getAllEmbeddedObjects(documentToGetFrom, fileFieldName)
{
var rit1:NotesRichTextItem = getFirstNotesRichTextItem(documentToGetFrom, fileFieldName);
if (rit1 == null)
{
return(null);
}
try
{
var arr=rit1.getEmbeddedObjects();
return arr;
}
catch(e)
{
return(null);
}
}
According to plain logic, I need to do the following in order to make it work:
Get attachments from the document A
Copy them to the document B
Remove attachments from the document A
Call save() on A
Call save() on B
I did exactly the same, but nevertheless get this nasty exception. Also, I've tried to solve the problem by setting OLEDisableFX to 1, but with no luck. I assume that something must be wrong with the method copyItem() (I guess it can only work properly with simple datatypes). What's the problem? Thanks in advance.
You'll probably need to detach the attachment from the source document and attach it to the target document. See the NotesEmbeddedObject class for examples.
Use the CopyItemToDocument method of the NotesItem class. The following is some code I used in a LotusScript agent but the CopyItemToDocument method is also available in Java and SSJS.
If doc.Hasitem("RTF1") Then
Set item = Nothing
Set item = doc.getFirstItem("RTF1")
Call item.Copyitemtodocument(targetdoc, "targetRTF")
Call item.Remove()
End If

Error when i delete multiple rows "The object cannot be deleted because it was not found in the ObjectStateManager."

Hey Everyone i am using this code to remove multiple records in table. but it's give me an error.
"The object cannot be deleted because it was not found in the
ObjectStateManager"
I am new in EF please help me what's wrong in my code.
listOfEntities = list of record which i want to delete from table
U = it is a type entity
using (var db = new DMContext())
{
db.SaveChanges();
}
It means that the entity is not attached. You can try like this
using (var db = new DMContext())
{
db.YourTableEntity.Attach(EntityToRemove);
db.YourTableEntity.Remove(EntityToRemove);
db.SaveChanges();
}
You cannot remove the entities which are detached, so you need to first attach them and then you can remove it.
To remove multiple records
foreach (var entity in entities)
{
Set<T>().Attach(entity);
Set<T>().Remove(entity);
}
SaveChanges();

Is there a C# implementation of Redis-rdb-tools?

Taking a look at Redis-RDB-Tools, it looks like there are some useful functions for monitoring the health of your Redis server.
ServiceStack.Redis seems to have a good set of client functions (but I'm using BookSleeve).
Are there any C# implementations that give me some basic health checks - consumed memory, disk usage, etc?
-- UPDATE --
Thanks to BookSleeve's GetInfo() command, the following is returned... however I should have been more specific: Is there a way of getting back the server info as parameters/object properties or a pre-packaged way of parsing the output values?
Here is the output from GetInfo():
"# Server\r\nredis_version:2.6.10\r\nredis_git_sha1:00000000\r\nredis_git_dirty:0\r\nredis_mode:standalone\r\nos:Linux 2.6.32-279.19.1.el6.x86_64 x86_64\r\narch_bits:64\r\nmultiplexing_api:epoll\r\ngcc_version:4.4.6\r\nprocess_id:2492\r\nrun_id:62402d583871f4b83f469917966aed8d163d02f3\r\ntcp_port:6379\r\nuptime_in_seconds:502354\r\nuptime_in_days:5\r\nlru_clock:1928056\r\n\r\n# Clients\r\nconnected_clients:7\r\nclient_longest_output_list:0\r\nclient_biggest_input_buf:175\r\nblocked_clients:0\r\n\r\n# Memory\r\nused_memory:1402576\r\nused_memory_human:1.34M\r\nused_memory_rss:9719808\r\nused_memory_peak:1675192\r\nused_memory_peak_human:1.60M\r\nused_memory_lua:31744\r\nmem_fragmentation_ratio:6.93\r\nmem_allocator:jemalloc-3.2.0\r\n\r\n# Persistence\r\nloading:0\r\nrdb_changes_since_last_save:3035\r\nrdb_bgsave_in_progress:0\r\nrdb_last_save_time:1360955487\r\nrdb_last_bgsave_status:ok\r\nrdb_last_bgsave_time_sec:-1\r\nrdb_current_bgsave_time_sec:-1\r\naof_enabled:0\r\naof_rewrite_in_progress:0\r\naof_rewrite_scheduled:0\r\naof_last_rewrite_time_sec:-1\r\naof_current_rewrite_time_sec:-1\r\naof_last_bgrewrite_status:ok\r\n\r\n# Stats\r\ntotal_connections_received:18822\r\ntotal_commands_processed:12547\r\ninstantaneous_ops_per_sec:3\r\nrejected_connections:0\r\nexpired_keys:0\r\nevicted_keys:0\r\nkeyspace_hits:374\r\nkeyspace_misses:39\r\npubsub_channels:1\r\npubsub_patterns:0\r\nlatest_fork_usec:0\r\n\r\n# Replication\r\nrole:master\r\nconnected_slaves:0\r\n\r\n# CPU\r\nused_cpu_sys:57.82\r\nused_cpu_user:208.63\r\nused_cpu_sys_children:0.00\r\nused_cpu_user_children:0.00\r\n\r\n# Keyspace\r\ndb0:keys=6,expires=0\r\n"
With regards to the updated question: the information there is not currently exposed as "parsed", but that sounds like a reasonable thing to add; I suspect I'll hide the GetInfo() method, move it to .Server.GetInfo(), and expose it in a parsed form. The code to split it already exists, though - but as a private method: RedisConnectionBase.ParseInfo:
static Dictionary<string, string> ParseInfo(string result)
{
string[] lines = result.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
var data = new Dictionary<string, string>();
for (int i = 0; i < lines.Length; i++)
{
string line = lines[i];
if (string.IsNullOrEmpty(line) || line[0] == '#') continue; // 2.6+ can have empty lines, and comment lines
int idx = line.IndexOf(':');
if (idx > 0) // double check this line looks about right
{
data.Add(line.Substring(0, idx), line.Substring(idx + 1));
}
}
return data;
}
Call Redis's INFO command, it provides all the different server info stats inside a redis-server.
Here's a page dump of all the available stats on a 2.5.12 version of redis-server.

How can I update a content item (draft) from a background task in Orchard?

I have a simple IBackgroundTask implementation that performs a query and then either performs an insert or one or more updates depending on whether a specific item exists or not. However, the updates are not persisted, and I don't understand why. New items are created just as expected.
The content item I'm updating has a CommonPart and I've tried authenticating as a valid user. I've also tried flushing the content manager at the end of the Sweep method. What am I missing?
This is my Sweep, slightly edited for brevity:
public void Sweep()
{
// Authenticate as the site's super user
var superUser = _membershipService.GetUser(_orchardServices.WorkContext.CurrentSite.SuperUser);
_authenticationService.SetAuthenticatedUserForRequest(superUser);
// Create a dummy "Person" content item
var item = _contentManager.New("Person");
var person = item.As<PersonPart>();
if (person == null)
{
return;
}
person.ExternalId = Random.Next(1, 10).ToString();
person.FirstName = GenerateFirstName();
person.LastName = GenerateLastName();
// Check if the person already exists
var matchingPersons = _contentManager
.Query<PersonPart, PersonRecord>(VersionOptions.AllVersions)
.Where(record => record.ExternalId == person.ExternalId)
.List().ToArray();
if (!matchingPersons.Any())
{
// Insert new person and quit
_contentManager.Create(item, VersionOptions.Draft);
return;
}
// There are at least one matching person, update it
foreach (var updatedPerson in matchingPersons)
{
updatedPerson.FirstName = person.FirstName;
updatedPerson.LastName = person.LastName;
}
_contentManager.Flush();
}
Try to add _contentManager.Publish(updatedPerson). If you do not want to publish, but just to save, you don't need to do anything more, as changes in Orchard as saved automatically unless the ambient transaction is aborted. The call to Flush is not necessary at all. This is the case both during a regular request and on a background task.

Resources