Create SharePoint IF function Workflow - sharepoint-workflow

I am trying to update the date in a column based on the information contained in another column. I know it will be an "IF" function, but I am not getting the formula correct.
I need to update the due date column by adding the time based from the frequency columnn(week, day, month, etc...) to the completion date column....please help!

I would not use the Designer inside Visual Studio to handle an If-Clause. Reason: I didn't figure out how to use this and from other things lieke the While-Activity I read that this is much slower than a coded one.
For some handsome looking I would add "CodeActivity" and link/ invoke my method to this. Inside this method you could use
string frequency = workflowProperties.Item["name of other column"].ToString();
string oldDate = workflowProperties.Item["name of updating column"].ToString();
DateTime newDate = Convert.ToDateTime(oldDate);
if (String.Equals(frequency, "weekly", StringComparison.OrdinalIgnoreCase))
{
<your code like:> workflowProperties.Item["name of updating column"] = newDate.AddDays(7);
}
else if (...)
or use switch (frequency){}
Remind that workflowProperties.Item refers everytime to selected Item. Because this is a global variable inside your workflow, you can access to it from every method. If you don't understand this example, be free to ask.
Shegit

Related

Hyperledger Composer - DateTime storage in asset

This question is based upon my attemp to adapt the sample 'perishable-network' (https://github.com/hyperledger/composer-sample-networks/tree/master/packages/perishable-network) for my work.
Suppose I have an hyperledger composer asset called ShippingContract. Now I'd like to record the contract creation time in this asset (say when a createContract() function is called ). How can I achieve this? I was using a DateTime member which was being set in chaincode.
The few articles/posts (some on SO itself) that talk about this suggest that we should not store random/current time in DateTime object through chaincode, as during consensus, each endorsing/committing node will come up with different value and lead to failure of transaction!
The perishable-network sample uses a DateTime member variable, but sets this using the setupdemo transaction timestamp value within the setupDemo transaction code itself!
const tomorrow = setupDemo.timestamp;
tomorrow.setDate(tomorrow.getDate() + 1);
contract.arrivalDateTime = tomorrow;
First question: How is it possible to refer to the transaction timestamp within the same transaction itself? Is this timestamp set when endorsers first endorse the transaction?
Second question:
I was thinking that instead of DateTime member variable, it might be better to use a String variable and set that to new Date().toString() (Javascript function) and then pass it as a parameter to the transaction processor function (instead of calculating it at run-time within the function). This way, since I'm passing in a fixed value instead of having the chaincode calculate it dynamically, I hope to overcome any issues with consensus.
Is this a good approach? Any issues therein? Any better way to do this?

How to do string functions on a db table column?

I am trying to do string replace on entries of a column inside a db table. So far, I have reached till here:
$misa = DB::table('mis')->pluck('name');
for($i=0;;$i++)
{
$misa[$i] = substr_replace("$misa[$i]","",-3);
}
The error I am getting is "Undefined offset:443".
P.S. I am not a full-fledged programmer. Only trying to develop a few simple programs for my business. Thank You.
Since it's a collection, use the transform() collection method transform it and avoid this kind of errors. Also, you can just use str_before() method to transform each string:
$misa = DB::table('mis')->pluck('name');
$misa->transform(function($i) {
return str_before($i, ':ut');
});
There are a few ways to make this query prettier and FASTER! The beauty of Laravel is that we have the use of both Eloquent for pretty queries and then Collections to manage the data in a user friendly way. So, first lets clean up the query. You can instead use a DB::Raw select and do all of the string replacing in the query itself like so:
$misa = DB::table('mis')->select(DB::raw("REPLACE(name, ':ut' , '') as name"));
Now, we have a collection containing only the name column, and you've removed ':ut' in your specific case and simply replaced it with an empty string all within the MySQL query itself.
Surprise! That's it. No further php manipulation is required making this process much faster (will be noticeable in large data sets - trust me).
Cheers!

codeigniter update register based on date

I am developing a news application where users introduce news and the creation date gets stored and the news appears with a "new!" icon next to it. I would like to automatically erase the "new" icon when the news becomes old (let's say 1 week).
How can I automatically implement this feature? I would like to update a field of a table (new for instance) based on "it is 1 week later than when the news was introduced by the user".
Do I need a "timer" for every new register created? Do I need some sort of cron job to check wether a news is outdated or not?
How would you do it?
Thanks!
Not sure how your app works as you didn't provide any code, but you can do it easly in your view:
if(time() - strtotime($postDate) <= 60*60*24*7) //$postDate is the date stored in your table
{
echo "<div>new!</div>"
}
if you want to do that with a db field, look at how crons work :
https://en.wikipedia.org/wiki/Cron
You could try something like the following:
$news_time = strtotime($row['creation_date']); // your database record creation date
$a_week_ago = strtotime('-1 week');
if( $news_time > a_week_ago ) {
// Your 'new' HTML here
}

retrieve the Quote Detail with c#

I'm trying to create a custom workflow (for Dynamics CRM 2011) which must send an email with information on the Details Quote from a quote.
I create it in Visual Studio 2010 with the sdk.
The workflow is triggered manualy from a quote.
I am able to retrieve the value of the customerid, but I am unable to get the attached documents or the quotedetails of the Quote, when I launched the workflow I have this exception :
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Microsoft.Xrm.Sdk.Entity.get_Item(String attributeName)
at CPageCRM.Workflow.QuoteSendMailNotificationRIP.Execute(CodeActivityContext executionContext)
My code is :
//to get the current Quote
Entity preImageEntity = context.PreEntityImages.Values.FirstOrDefault();
//preImageEntity is a Quote because I trigger the workflow from a Quote
//the next two lines work, I can retrieve the good value of the Quote
string natureDevis = Utils.GetOptionSetValueLabel(service, preImageEntity, "new_nature", (OptionSetValue)preImageEntity["new_nature"]);
string prospectDevis = ((EntityReference)preImageEntity["customerid"]).Name;
//I get the exception after that :
List<QuoteDetail> listQuoteDetail = new List<QuoteDetail>();
listQuoteDetail = preImageEntity["quote_details"] as List<QuoteDetail>; //I get the exception
I don't understand why the quote_details doesn't exist in the dictionnary, because when I do :
Quote devis = new Quote();
devis.quote_details //<= (the autocompletion is working)
I have the same problem when I try to get sharepointdocumentlocation
Anyone have an explication? How can I retrieve the Quote Details and the document attached to my Quote from the code?
Thanks
A comment and potential answer.
My comment is when retrieving stuff out of the Images I often find it easier to let the compiler grab the proper type and just use 'var'.
My answer is that quote_details isn't just a field, but an actual 1-n relationshp (by looking in the metadata browser). You may need to get the related entities in a separate retrieve.
Edit:
For example: _service.Retrieve("quote", quoteId, new ColumnSet("quote_details"))
will retrieve the quote details from the service. However, you could also check and see if you are passing in the quote_details attribute from the PreImage.
I successed with a linq query
I had to search the quote_detail which were linked to the quote :
var queryQuoteDetail = from r in orgServiceContext.CreateQuery("quotedetail")
where ((EntityReference)r["quoteid"]).Id.Equals(context.PrimaryEntityId)
select r;

Forcing JQuery Datatable to load data via AJAX upon selection of a date range

I have the wonderful jquery data tables currently loading data using ajax.
The code is pretty much the same as the example I took it from which can be found at: http://www.datatables.net/release-datatables/examples/server_side/pipeline.html
I found this the best example because it incoporates pagination, sorting and also the search box into the ajax requests. The search box allows you to type in key words and this triggers the ajax function which includes the search value as a $_GET var to the server script.
This is a small preview of my table with table tools etc. loaded.
http://img828.imageshack.us/img828/9778/previewxjh.png
As you can see the main focus here is the filament groups date range plugin which I have added. I have finished with this now, and have a fail safe for the duplicate event firing problem etc. its ready to go and just needs including in the ajax pipeline - which is where I have been stuck for the last day or so.
fnDataTablesPipeline appears to be just an interim and doesnt reference the search box at all, so I can't figure out how the search box is working, and I am unsure if this is the right place to go including my date range value (everything I have tried just leads me to a dead end)
I want to use my onChange event for the date range filter, and apply it exactly the same way that the search box works. When the value is changed, simply pass it as a get variable so that my php script can deal with it there. I have concerns regarding the paging, and I will probably need to just reset back to page one after the date is changed (not sure how I am going to deal with this just yet, but thats the next step)
I need help telling datatables to refresh from the ajax source, and include the date range as a get parameter to the server side script (like when the search box value changes)
- sounds straight forward, but this is where I am breaking down and not making good use of my time due to the lack of understanding.
Is there anyone that has implemented similar that can help me?
The biggest problem right now is how to force the refresh from my date range onChange event, and of course include the single string value which contains my dates (which I know how to cover server side)
Many Thanks,
Chris
EDIT: I actually managed to get this working before I finished for the day. I'll post my code when I get back in the office tomorrow, it was actually surprisingly easy - I was tackling it completely wrong.
After changing date..
oTable.fnClearTable(0);
oTable.fnDraw();
Include var in pipeline
function fnDataTablesPipeline ( sSource, aoData, fnCallback, dateRange ) {
aoData.push( { "name": "dateRange", "value": $('#dateRangePicker').val(), } );
...
Obtain var in php script
$_GET['dateRange']

Resources